简体   繁体   中英

Create a DialogFragment with a transparent background

I have searched for an answer to this question but none of the answers helped me.

The problem is that I have a DialogFragment that is displayed when a user add a widget (as part of the WidgetConfig). It looks like this:

在此处输入图片说明

The dialog is created like this;

Calling activity:

public class AppWidgetConfigure extends Activity {

    private void setUp(){

        //Config widget code removed 

        DialogFragment dialog = new ChooserDialog();
        dialog.show(getFragmentManager(), "dialog");
    }
}

the DialogFragment:

public class ChooserDialog extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        choices = getResources().getStringArray(R.array.choices);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());       
        builder.setTitle(getResources().getString(R.string.widget_dialog_chooser_title));
        builder.setPositiveButton(getResources().getString(R.string.widget_dialog_chooser_posBtn), this);
        builder.setNegativeButton(getResources().getString(R.string.widget_dialog_chooser_negBtn), this);   
        builder.setSingleChoiceItems(choices, -1, this);
        return builder.create();

    }
}

I want the dialog to have a transparent background . Currently, as shown in the picture, there is the WidgetConfigure activity as background.

Thankful for any help.

Marcus

Using below code we can get transparent AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),android.R.style.Theme_Translucent);

But in your case you have some choices to be displayed in alert dialog. In that case you need to create a layout with transparent background with choice list and set that layout to dialog.

something like this

View view = getActivity().getLayoutInflater().inflate(R.layout.dialog, null);
builder.setView(view);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM