mudit
mudit

Reputation: 25536

How to change the background of Android Alert Dialog Title

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.

Upvotes: 8

Views: 14301

Answers (2)

AndDoc
AndDoc

Reputation: 1

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.Theme_AlertDialog);

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

Upvotes: 0

Dixit Patel
Dixit Patel

Reputation: 3192

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.

Upvotes: 6

Related Questions