gpt4 book ai didi

android - AlertDialog 标题下划线颜色

转载 作者:行者123 更新时间:2023-11-29 00:41:11 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com