【问题标题】:How to color the divider of the Alertdialog.builder in android?如何在android中为Alertdialog.builder的分隔线着色?
【发布时间】:2015-02-19 01:15:26
【问题描述】:

我正在使用 AlertDialog.Builder 类来构建带有单选按钮和取消按钮的警报,我想更改分隔线的颜色和单选按钮的颜色如何做到这一点任何人都可以提供解决方案。我检查了stackoverflow中关于这个相关问题的所有答案。 还有一个我正在使用 v7Appcomapact 库。我的 min sdk 是 10,最大值是 18。我不想使用自定义布局。

【问题讨论】:

  • v7Appcomapact 不提供AlertDialogs 的自定义如果你想实现Material Dialogs 你可以试试这个库github.com/afollestad/material-dialogs
  • 我的项目低版本是 18 而不是 21?我可以使用那个库。
  • 是的,你可以使用上述库
  • 谢谢...但我设法改变分隔线的颜色...

标签: android


【解决方案1】:

试试这个

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

【讨论】:

  • 我说我之前已经从 stackoverflow 中看到了所有答案。你给我的函数是 AlertDialog 我想要的 AlertDialog.builder。如果我在你的函数中使用 AlertDialog.Builder 在“getWindow()”处给我一个错误,错误是无法解析方法“getWindows()”。
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2011-01-23
  • 2014-11-08
  • 2017-07-02
  • 1970-01-01
  • 2011-11-12
  • 2015-12-01
相关资源
最近更新 更多