2014-10-02 32 views
8

Tôi đang cố thay đổi màu văn bản và phông chữ của tiêu đề "Nhập chi tiết" mà bạn có thể nhìn thấy trong ảnh chụp nhanh bên dưới nhưng không thể thực hiện được. Làm ơn hãy giúp tôi giải quyết vấn đề này.Cách định cấu hình tiêu đề của Đối thoại Alert

Code: -

public class MainActivity extends Activity { 
Button cust; 
Dialog custom; 
EditText Fname; 
EditText Lname; 
TextView txt; 
Button savebtn; 
Button canbtn; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     cust = (Button)findViewById(R.id.cusdia); 
     txt = (TextView)findViewById(R.id.txt); 
     cust.setOnClickListener(new View.OnClickListener() 
     { 
      String fname,lname; 
      @Override 
      public void onClick(View view) { 
       // TODO Auto-generated method stub 
       custom = new Dialog(MainActivity.this); 
       custom.setContentView(R.layout.dialog); 

       Fname = (EditText)custom.findViewById(R.id.fname); 
       Lname = (EditText)custom.findViewById(R.id.lname); 
       savebtn = (Button)custom.findViewById(R.id.savebtn); 
       canbtn = (Button)custom.findViewById(R.id.canbtn); 
       custom.setTitle("Enter Details"); 

       savebtn.setOnClickListener(new View.OnClickListener() 
       { 

        @Override 
        public void onClick(View view) { 
         // TODO Auto-generated method stub 
         fname = Fname.getText().toString(); 
         lname = Lname.getText().toString(); 

         txt.setText("Your Name is "+fname +lname); 
         custom.dismiss(); 
        } 

       }); 

cảnh báo hộp thoại Snapshot

ALert Dialogue box

+0

bạn phải làm cho tấm phong cách riêng của bạn cho rằng hoặc nếu có cỡ chữ hoặc màu văn bản sẵn thì bạn có thể thay đổi nó trong file xml – Umair

Trả lời

2

Thêm đoạn mã sau vào style.xml

<style name="MyDialog" parent="@android:style/Theme.Dialog"> 

    <item name="android:typeface">monospace</item> 
    <item name="android:textColor">#ff4444</item> 

</style> 

and set your dialog like following

d = new Dialog(Inquiry.this,R.style.MyDialog); 

Tôi chắc chắn, bạn sẽ nhận được những gì bạn muốn.

+0

Cảm ơn, Cuối cùng tôi có thể để giải quyết vấn đề này. Cảm ơn rất nhiều!! :) –

0

bạn chỉ có thể sử dụng

 new AlertDialog.Builder(this) 
    .setCustomTitle(customTitleView) 

và cho customTitleView tạo view ví dụ như một TextView và thiết lập fontcolor cho nó.

2

bạn có thể sử dụng bên dưới code.create hộp thoại tùy chỉnh bằng tệp xml và tránh thanh tiêu đề mặc định. thay vì thanh tiêu đề mặc định, bạn có thể sử dụng textview trong tệp xml và cũng sử dụng kiểu dưới đây trong mã java.

Dialog dialog = new Dialog(DetailsActivity.this, R.style.FullHeightDialog); 
    dialog.setContentView(R.layout.insert_text_dialog); 

phong cách

<style name="FullHeightDialog" parent="android:style/Theme.Dialog"> 
    <item name="android:windowNoTitle">true</item> 
</style> 
Các vấn đề liên quan