2

I'm using the following code to theme my AlertDialogs.

Resources resources = dialog.getContext().getResources();
int color = resources.getColor(R.color.green_theme); // your color here

int alertTitleId = resources.getIdentifier("alertTitle", "id", "android");
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
alertTitle.setTextColor(color); // change title text color

int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(color); // change divider color

It works well, except for the case where I have an AlertDialog with a message but no title. It appears that there is a third View that is only displayed in this case, which also needs to have its color set. I just don't know what the id of this View is. Does anyone know it?

The View I'm talking about is highlighted in the white rectangle in the picture below.

AlertDialog

zholmes1
  • 539
  • 5
  • 21

3 Answers3

3

I guess that no one actually read my question.

Anyways, here's the answer if anyone else has his issue:

int titleDividerTopId = resources.getIdentifier("titleDividerTop", "id", "android");
View titleDividerTop = dialog.getWindow().getDecorView().findViewById(titleDividerTopId);
titleDividerTop.setBackgroundColor(color);
zholmes1
  • 539
  • 5
  • 21
1
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

That should get rid of the title.

Donn Felker
  • 9,553
  • 7
  • 48
  • 66
  • I don't want to get rid of it, I want to change the color so that it matches the text. – zholmes1 Oct 10 '14 at 06:15
  • 1
    AFAIK, thats part of the theme you're using. You'll have to adjust the theme. Here's a SO post: http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – Donn Felker Oct 10 '14 at 06:18
0

Do one thing just change the theme of your whole application as transparent in your manifest file's application tag as below:

Which will not show your blue line in your dialog.

  <application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" >
GrIsHu
  • 29,068
  • 10
  • 64
  • 102