Arslan Ali Arslan Ali - 3 months ago 30
Android Question

Show only button from custom layout alert dialog

enter image description here

I am developing an app in which i have to show a button on the screen which is shown in the screenshot. But i want to show this button on some other activity.
e.g. I have an activity which is on the screen. now after two minutes i want to show a custom alert dialog i.e. this screen which is shown in the screenshot but instead of showing only button, the alert dialog is showing whole screen as a dialog i.e with the white background. How can i get rid of this background so that only this button can be shown on the screen as an alert dialog?
My code for this custom layout is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
android:orientation="vertical" android:layout_width="match_parent"

android:text="Unable to Snooze"
android:layout_marginBottom="15dp" />

and activity code for alert dialog is:

new Handler().postDelayed(new Runnable() {
public void run() {

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ActivityA.this);
LayoutInflater inflater = ActivityA.this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert, null);

AlertDialog alert11 = dialogBuilder.create();;

}, 120000);

NOTE I want to show the button on the bottom of the screen as an alertdialog



Use Dialog instead of AlertDialog.Builder and so use setContentView instead setView. And check this one: Dialog with transparent background in Android

Old Answer:

If you are gonna show this button on multiple activities, you'd better use DialogFragment. Also you can set fragments background transparent and you can adjust size of the dialog to fit button.

How to use Dialog Fragment :