【问题标题】:AlertDialog title underline colorAlertDialog 标题下划线颜色
【发布时间】:2012-02-11 11:13:55
【问题描述】:

有没有办法改变 AlertDialog 中标题下划线的颜色? 我已经通过自定义样式定义更改了标题颜色(见下文),但我没有找到下划线的任何 xml 属性。

    <style name="CustomTitle" parent="@android:style/TextAppearance.Holo">
    <item name="android:textColor">@color/green</item>
    </style>

我正在运行 Android 4。

编辑:这就是我创建 AlertDialog 的方式

        Builder ad = new AlertDialog.Builder(new ContextThemeWrapper(this,
            R.style.DialogPrivate));
    ad.setTitle("Custom Dialog");

    ad.setMessage("blaaaaa");
    ad.setPositiveButton("test", null);
    ad.setNegativeButton("test2", null);
    ad.show();

以及现在的样子Screenshot

【问题讨论】:

标签: android android-alertdialog custom-titlebar


【解决方案1】:

下划线实际上是一个 View 对象,其背景颜色设置为默认的全息蓝色(至少在 jellybean 上)。

您可以在以下位置查看警报对话框的布局:https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/alert_dialog_holo.xml#L58。具体来说,titleDivider 视图:

<View android:id="@+id/titleDivider"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:visibility="gone"
        android:background="@android:color/holo_blue_light" />

这很不幸,因为这意味着如果没有一些丑陋的、hacky 代码,就无法自定义视图的颜色,例如:

void changeUnderlineColor(AlertDialog d, int color) {
    final ViewGroup v = (ViewGroup) d.getWindow().findViewById(android.R.id.content);
    v.findViewById(getResources().getIdentifier("titleDivider", "id", "android")).setBackgroundColor(color);
}

这适用于使用 holo_light 主题的 Jellybean,但几乎可以肯定这是一个坏主意。如果你真的想改变线条的颜色,看起来你需要自己构建一个完全自定义的对话框

【讨论】:

    【解决方案2】:

    这个回复有点晚了,但我相信“下划线”实际上是用作背景的 9 个补丁图像文件的一部分。您将需要更改该背景图像以更改颜色。

    【讨论】:

      【解决方案3】:

      尝试使用 android:textColorLink="#783302"

      【讨论】:

      • 不幸的是,这个属性的颜色保持不变。 @color/privateColor
      猜你喜欢
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 2016-09-03
      • 2019-02-13
      • 2010-09-16
      • 1970-01-01
      相关资源
      最近更新 更多