仅更改AlertDialog中的字体大小

时间:2014-08-19 23:30:13

标签: android customization alertdialog font-size msgbox

我知道这已经被问过,甚至已经回答,但我无法弄清楚如何自定义AlertDialog。

我写下面的代码,我得到以下结果作为AlertDialog,这是我想要的除了字体大小:它是我唯一想要改变的。

@Override
public void onClick(View v) {               
    final AlertDialog msgbox  = new AlertDialog.Builder(About.this).setTitle("Credits").setMessage(msg).create();
    msgbox.setCancelable(true);
    msgbox.show();
}

enter image description here

在这里阅读其他一些答案我写下面的代码并得到以下对话框:

@Override
public void onClick(View v) {       
    final TextView myView = new TextView(getApplicationContext());
    myView.setText(msg);
    myView.setTextSize(14);
    final AlertDialog msgbox  = new AlertDialog.Builder(About.this).setTitle("Credits").setView(myView).create();           
    msgbox.setCancelable(true);
    msgbox.show();
}

enter image description here

正如你所看到的,它改变了一切!如何只更改字体大小或如何使视图显示为以前的AlertDialog?

1 个答案:

答案 0 :(得分:2)

如果您只想更改AlertDailog的文本大小,可以通过其ID(已定义 - android.R.id.message)访问Dialog上的本机TextView资源并更改大小。但非常重要的是,您必须在调用show()后进行更改,因此本地TextView已被绘制并准备就绪。在使用{{1}创建Dialog后,请执行此操作。 }}:

Dialog.Builder