mike
mike

Reputation: 1338

Setting background to a dialog

I have a dialog that comes up in my app and I wanted to stray away from using the default dialog, to give something slightly more customized. In my dialog layout, I included the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/My_Custom_Background">

This does basically what I want it to, it changes the background as expected. However, this only applies to the layout of the contents of the dialog box: the dialog also has a title and the title part of the dialog box is still the default Android theme, then everything under it is customized as I wanted. Is there away to extend the custom background to the entire dialog box?

Upvotes: 0

Views: 922

Answers (3)

user1952459
user1952459

Reputation:

you can create your dialog as below

Dialog mDialog = new Dialog(mContext);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    mDialog.setContentView(R.layout.your_custom_dialog_layout);
    mDialog.setCancelable(false);
    mDialog.show();

and inside your custom layout, you can set the custom drawable as a background.

Upvotes: 2

You need to remove the title bar

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

Make sure to call requestWindowFeature() before the setContentView() otherwise you get a FATAL EXCEPTION

Upvotes: 2

Vikram Singh
Vikram Singh

Reputation: 1420

An alternate is to remove your dialog titlebar using this...

yourdialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

and design whole dialog with title inside your layout...

Upvotes: 0

Related Questions