nil*_*ash 11 android styles dialog colors android-alertdialog
我想在警告对话框中设置样式或更改标题标题的分隔颜色.我搜索这个问题,我想很多人都在寻找这个.但我仍然无法找到正确的解决方案.我想改变以下内容.

Mat*_*Dev 15
你可以通过一个非常简单的hack来改变AlertDialog标题的颜色:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
Teo*_*ald -1
从来源来看,这种颜色似乎是硬编码的。我认为这是一个错误,恕我直言,它应该是可设计的。
不过,有一个简单的解决方法:使用setStyle(DialogFragment.STYLE_NO_TITLE, R.style.myStyle);,并编写一个简单的线性布局,其中第一项是您的标题。