2

Is there a way to change the color of the title underline in an AlertDialog? I already changed the title color through a custom style definition (see below), but I didn't found any xml attribute for the underline.

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

I'm running Android 4.

Edit: That's how I create the 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();

And how it looks like at the moment Screenshot

user1173367
  • 51
  • 1
  • 4

3 Answers3

2

The underline is actually a View object with its background color set to the default holo blue (on jellybean atleast).

You can see the layout for alert dialogs at: https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/alert_dialog_holo.xml#L58. Specifically, the 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" />

Thats unfortunate, because it means there's no way to customise the color of the view without some ugly, hacky code such as:

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);
}

This works on Jellybean using the holo_light theme, but it's almost certainly a bad idea. If you really want to change the color of the line, looks like you'll need to build a completely custom Dialog yourself

DanielGrech
  • 1,402
  • 12
  • 16
1

This response is a bit late, but I believe that the "underline" is actually part of a 9 patch image file used as a background. You will need to change that background image to change the color.

Tad
  • 4,668
  • 34
  • 35
-1

try using android:textColorLink="#783302"

user1203673
  • 1,015
  • 7
  • 15