8

I want to change the background of the Alert dialog. I have tried following code piece to do so:

 <style name="Theme.AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog">
        <item name="android:background">@android:color/transparent</item>
        <item name="android:textColor">#659F26</item>
        <item name="android:windowTitleStyle">@style/Theme.AlertDialog.Title</item>
    </style>

    <style name="Theme.AlertDialog.Title" parent="@android:style/TextAppearance.DialogWindowTitle">
        <item name="android:background">@drawable/cab_background_top_example</item>
    </style>

Java Code:

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.Theme_AlertDialog);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctw);

alertDialogBuilder.setTitle(getResources().getString(R.string.confirmation));   
alertDialogBuilder.setMessage(getResources().getString(R.string.msg));       
alertDialogBuilder.show();

My app is showing dialog like this:

enter image description here

while i want it to look like:

enter image description here

Please suggest, what i am doing wrong.

mudit
  • 25,306
  • 32
  • 90
  • 132
  • Does this answer your question? [How to remove the title in Dialog?](https://stackoverflow.com/questions/7633990/how-to-remove-the-title-in-dialog) – General Grievance Sep 02 '22 at 16:51

2 Answers2

6

Use this code when creating a dialog:

 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   

create your own layout As many customise done with title then set your layout

  dialog.setContentView(R.layout.yourlayout);

NOTE: use

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); before     
dialog.setContentView(R.layout.yourlayout);

otherwise it give error.

Dixit Patel
  • 3,190
  • 1
  • 24
  • 36
0
ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.Theme_AlertDialog);

In this line use instead of "this" use ActivityName.this

duggu
  • 37,851
  • 12
  • 116
  • 113
AndDoc
  • 1