2

有没有办法改变 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();

以及现在的样子截图

4

3 回答 3

2

下划线实际上是一个 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,但几乎可以肯定这是一个坏主意。如果您真的想更改线条的颜色,看起来您需要自己构建一个完全自定义的对话框

于 2013-04-11T04:42:03.233 回答
1

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

于 2012-10-09T21:29:37.497 回答
-1

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

于 2012-02-11T12:16:46.610 回答