如何通过 ArrayList 更改字体大小并将其设置为 AlertDialog.Builder

How to change front size and Set it mid AlertDialog.Builder by ArrayList

这是我的代码 想把front size改成mid,但是例子很少说明。感谢帮助。

painList = new ArrayList<>(); 

painList.add(getString(R.string.painL1));
painList.add(getString(R.string.painL2));

new AlertDialog.Builder(Clear.this)

.setTitle("AAA")
.setItems(
painList.toArray(new String[painList.size()]),
new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog,
    int which) {
        if (which == 0) {
            Intent go = new Intent();
            go.setClass(Clear.this, Pain.class);
            startActivity(go);
        }
        if (which == 1) {
            Intent go = new Intent();
            go.setClass(Clear.this, Clear.class);
            startActivity(go);
        }
    }
}).show();

谢谢!!

您必须为对话框使用样式。 例如在 values res 文件夹中创建 my_dialog_style.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyDialogStyle" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">#FF000000</item>
        <item name="android:textSize">16sp</item>
    </style>
</resources>

然后将其应用于您的对话:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.MyDialogStyle));

设置文本引力的一种方法是使用如下方法:

TextView messageText = (TextView) alertDialog.findViewById(android.R.id.message);
        messageText.setGravity(Gravity.CENTER);