我想在警报对话框中设置样式或更改标题标题的分隔线颜色。我搜索了这个问题,我认为很多人都在搜索这个问题。但我仍然无法找到正确的解决方案。我想更改以下内容。
问问题
20357 次
4 回答
16
您实际上可以通过一个非常简单的 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();
}
}
于 2014-01-28T09:08:44.797 回答
4
分隔线颜色:-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.dialog)
.setIcon(R.drawable.ic)
.setMessage(R.string.dialog_msg);
Dialog d = builder.show();
int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = d.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.my_color));
于 2015-06-12T04:14:40.540 回答
-1
从来源来看,这种颜色似乎是硬编码的。我会认为这是一个错误,它应该是风格的恕我直言。
不过有一个简单的解决方法:使用setStyle(DialogFragment.STYLE_NO_TITLE, R.style.myStyle);
, 并编写一个简单的线性布局,其中第一项是您的标题。
于 2013-04-11T22:41:56.667 回答
-3
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context).
setTitle("Set IP Address").
setTitleColor("#FF00FF").
setDividerColor("#FF00FF").
setMessage("You are now entering the 10th dimension.").
qustomDialogBuilder.show();
于 2017-12-13T00:20:39.997 回答