android - AlertDialog标题下划线颜色

标签 android android-alertdialog custom-titlebar

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

最佳答案

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

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

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

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

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

关于android - AlertDialog标题下划线颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239751/

相关文章:

android - 更改背景android标题栏

android - 我的带有 ListView 的自定义标题未显示正确的高度和格式

android - Firebase 实时数据库 key 生成对于 Android/iOS 设备上的时钟更改是否可靠? #AskFirebase

android - 如何在jetpack compose中的特定位置绘制图像

java - 自定义对话框中的嵌套 LinearLayout 未显示

java - 在 Android 中无法同时关闭 2 个 AlertDialog

android - 发布 android 应用程序 : This app is incompatible with all of your devices

android - 为什么 findFirstVisibleItemPosition 不能按预期工作?

java - Android AlertDialog 将按钮对齐到底部不起作用

java - 自定义 Java 窗口标题栏菜单