2

How can I change the color of the line in a Dialog below:

Dialog title divider

Community
  • 1
  • 1
0xSina
  • 20,973
  • 34
  • 136
  • 253

3 Answers3

0

Unfortunately you'll have to inflate your own layout. Here's your answer:

How can I change the color of AlertDialog title and the color of the line under it

Community
  • 1
  • 1
Stan Smith
  • 896
  • 7
  • 19
0

create a custom AlertDialog and set custom title view using setCustomTitle.

 public AlertDialog.Builder setCustomTitle (View customTitleView)

Set the title using the custom view customTitleView. The methods setTitle(int) and setIcon(int) should be sufficient for most titles, but this is provided if the title needs more customization. Using this will replace the title and icon set via the other methods.

from this link.. http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setCustomTitle%28android.view.View%29

Libin
  • 16,967
  • 7
  • 61
  • 83
0

If you don't want to create a custom layout, you can access to the divider View using Resources.getIdentifier after subclassing AlertDialog then calling AlertDialog.findViewById. Here's a quick example:

/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final CustomDialog cd = new CustomDialog(this);
    cd.setTitle("Title");
    cd.setMessage("Message");
    cd.show();
}

private static final class CustomDialog extends AlertDialog {

    private CustomDialog(Context context) {
        super(context);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Resources res = getContext().getResources();
        final int id = res.getIdentifier("titleDivider", "id", "android");
        final View titleDivider = findViewById(id);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(Color.RED);
        }
    }
}

Example

adneal
  • 30,484
  • 10
  • 122
  • 151