How to create a completely custom Dialogue/Popup in Android (change overlay colour and dialogue window layout)

Viewed 44443

I would like to completely re-skin the default dialogue component in Android. Specifically I would like to do this:

  • Change the semi-transparent overlay background from the default black to a semi-transparent white.

  • Change the Dialogue window by removing the default windowed frame border, and replacing it with a layout defined in XML (it's just going to be a borderless graphic with floating buttons. no actual frame.)

I have seen tutorials about creating a custom layout for within the dialogue box (e.g. http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application), but I haven't seen anything regarding changing the colour of the overlay and/or completely customizing the dialogue window that pops up and turning it more into an overlay with no "window".

2 Answers

This worked great for me, but is missing how to close the dialog. if you have a button in your custom layout to close it, here is how to add the listener and close the dialog window.

final Dialog d = new Dialog(this,R.style.CustomDialogTheme);
d.setContentView(R.layout.custom_dialog);
d.show();

Button close_btn = (Button) d.findViewById(R.id.close_btn);
close_btn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        d.dismiss();
    }
});
Related