我知道这已经被询问甚至回答了,但我不知道如何自定义 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();
}
在这里阅读其他一些答案,我编写了以下代码并获得以下对话框:
@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();
}
如您所见,它改变了一切!如何仅更改字体大小或如何使 View 看起来像以前的 AlertDialog?
最佳答案
如果您只想更改 AlertDailog 的文本大小,您可以通过其 id(已定义 - android.R.id.message
)访问 Dialog 上的 native TextView 资源并改变大小。但非常重要的是,您必须在调用 show()
之后进行更改,以便绘制并准备好原生 TextView
。在创建您的 之后,这样做>Dialog
与 Dialog.Builder
:
final AlertDialog msgbox = new AlertDialog.Builder(About.this).setTitle("Credits").setView(myView).create();
msgbox.setCancelable(true);
msgbox.show();
TextView textView = (TextView) msgbox.findViewById(android.R.id.message);
textView.setTextSize(40);
关于android - 仅更改 AlertDialog 中的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25394586/