views:

2193

answers:

1

hello,I want to make a custom Dialog,because i donot like it"s style,i want get a rounded rectangle rather than rectangle . i know to implement it by theme in Manifest.xml . for example :the code at activity write: android:theme="@style/Theme.CustomDialog Theme.CustomDialog.xml

@drawable/filled_box true

filled_box.xml

my question is how to implement this Similar result by extends dialog or alertDialog. could you give me some code or other help? thank you

+2  A: 

In the constructor of your class that extends Dialog call super(context, R.style.CustomDialog); I've done this many times to create custom dialogs with specific themes.

However if the theme is the only thing about the Dialog that you want to change, you could try just instantiating an instance of the Dialog class and pass it the theme ID like Dialog dialog = new Dialog(context, R.style.CustomDialog);

An example of extending Dialog:

public class MyDialog extends Dialog
{
    public MyDialog(final Context context)
    {
        // Set your theme here
        super(context, R.style.MyDialogTheme);

        // This is the layout XML file that describes your Dialog layout
        this.setContentView(R.layout.myDialogLayout);  
    }
}

The rest of the code you will add to this class is going to be pretty much exactly like what you would write in an Activity class.

mbaird
yes ,thank you for your help .i used Dialog dialog = new Dialog(context, R.style.CustomDialog),the work very well.but I cannot write extends Dialog ,can you give me some Code snippets
pengwang
I added an example of extending Dialog.
mbaird