我正在使用 AlertDialog.Builder 类通过单选按钮和取消按钮构建警报,我想更改分隔线的颜色和单选按钮的颜色如何做到这一点,请提供解决方案。我检查了 stackoverflow 中关于此相关问题的所有答案。 还有一个我正在使用 v7Appcomapact 库。我的最小 sdk 是 10,最大是 18。我不想使用自定义布局。
最佳答案
试试这个
public static void brandAlertDialog(AlertDialog dialog) {
try {
Resources resources = dialog.getContext().getResources();
int color = resources.getColor(...); // your color here
int alertTitleId = resources.getIdentifier("alertTitle", "id", "android");
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
alertTitle.setTextColor(color); // change title text color
int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(color); // change divider color
} catch (Exception ex) {
ex.printStackTrace();
}}
已回答here
关于android - 如何在 android 中为 Alertdialog.builder 的分隔线着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577278/