2

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

Dialog title divider

2
  • why don't you create a custom dialog override the default dialog Mar 21, 2014 at 3:00
  • @PrimeMinisterofIndia I did, can you please explain a bit more how to do that?
    – 0xSina
    Mar 21, 2014 at 3:04

3 Answers 3

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.