android - 仅更改 AlertDialog 中的字体大小

标签 android customization android-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

如您所见,它改变了一切!如何仅更改字体大小或如何使 View 看起来像以前的 AlertDialog?

最佳答案

如果您只想更改 AlertDailog 的文本大小,您可以通过其 id(已定义 - android.R.id.message)访问 Dialog 上的 native TextView 资源并改变大小。但非常重要的是,您必须在调用 show() 之后进行更改,以便绘制并准备好原生 TextView。在创建您的 之后,这样做>DialogDialog.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/

相关文章:

android - HttpClient 未在 Android Studio 中导入

java - 如何将 "ellipsize"AlertDialog的标题放在中间?

android - 快速单击按钮时对话框打开两次

android - 使Android选项菜单不可点击

Android 上下文菜单不再出现在模拟器中

css - 重力形式 - 组织条件逻辑,带分节符的两列布局

javascript - ActiveAdmin - 自定义 Javascript 仅适用于特定资源,不适用于任何页面

java - 蜂窝状的蓝色和白色 AlertDialog

android - 使用抽屉导航时管理后退按钮行为的准则是什么?

django - Initial=True 不适用于 django 动态形式