android – 如何配置Alert Dialogue的标题

前端之家收集整理的这篇文章主要介绍了android – 如何配置Alert Dialogue的标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试更改文本颜色标题字体“输入详细信息”,您可以在下面的快照中看到但无法创建它.请帮我解决这个问题.

码:-

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();
                    }

                });

ALert对话框快照

解决方法

在style.xml中添加以下代码
<style name="MyDialog" parent="@android:style/Theme.Dialog">

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

</style>

并设置如下对话框

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

我相信,你会得到你想要的.

猜你在找的Android相关文章