Skip to content Skip to sidebar Skip to footer

Alertdialog Background Activity

I have an alert dialog that displays correctly as I intend it to. The problem is that when I trigger the alert from any activity, it opens what appears to be a blank layout then op

Solution 1:

Try this:-

To build an AlertDialog:

// 1. Instantiate an AlertDialog.Builder with its constructor
 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// 2. Chain together various setter methods to set the dialog characteristics
 builder.setMessage(R.string.dialog_message)
       .setTitle(R.string.dialog_title);

// 3. Get the AlertDialog from create()
 AlertDialog dialog = builder.create();

You can also refer the http://developer.android.com/guide/topics/ui/dialogs.html#DialogFragment for further reference.

Solution 2:

You can create a new Activity with a transparent background that has the Alert Dialog. Just launch this activity from anywhere in Application and you will get an Alert Dialog with your current Activity in Background:

To make the Activity transparent use below code:

<activityandroid:name="name of your Activity"android:excludeFromRecents="true"android:theme="@android:style/Theme.Translucent.NoTitleBar" />

Solution 3:

Try with this-

Viewv=getLayoutInflater().inflate(R.layout.activity_about_t2m, null);
    AlertDialogdialog=newAlertDialog.Builder(this)
    .setCancelable(false)
    .setView(v)
    .create();  
    dialog.setTitle("About T2M");
    dialog.show();

Post a Comment for "Alertdialog Background Activity"