简体   繁体   中英

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

this is my code I want to change my front size and let it in the mid, but the most example seldom explain it . thanks for help.

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

thanks!!

You must use style for dialog. For example create my_dialog_style.xml in values res folder:

<?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>

and then apply it for your dialog:

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

one way to set gravity of text is use something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM