アラート ダイアログのヘッダー タイトルの区切り線の色をスタイルまたは変更したいと考えていました。この質問について検索すると、多くの人がこれを検索していると思いますが、まだ正しい解決策を見つけることができません。これを次のように変更したい。
20357 次
4 に答える
16
非常に単純なハックで、実際に 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 に答える