2012-02-11 155 views
2

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

<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

+0

请参阅http://stackoverflow.com/questions/2394935/can-i-underline-text-in -an-android-layout – AliSh 2012-02-11 12:02:49

+0

你知道我如何访问标题TextView吗?我使用默认的AlertDialog,没有扩展它。 – user1173367 2012-02-11 12:47:57

回答

-1

尝试使用机器人: textColorLink =“#783302”

+0

不幸的是,颜色与此属性保持一致。 @ color/privateColor user1173367 2012-02-11 12:42:09

1

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

2

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

您可以在以下位置看到警报对话框的布局: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" /> 

那是不幸的,因为这意味着没有办法自定义视图的颜色没有一些丑陋,哈克这样的代码:

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主题,但它几乎肯定是一个坏主意。如果你真的想改变线的颜色,看起来像你需要自己建立一个完全自定义的对话框