Arslan Ali Arslan Ali - 26 days ago 19
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="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:text="Unable to Snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:id="@+id/button"
android:background="#088a68"
android:textColor="#FFFFFF"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp" />




and activity code for alert dialog is:

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

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

AlertDialog alert11 = dialogBuilder.create();
alert11.show();

}
}, 120000);


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

Answer

Edit:

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 : http://stackoverflow.com/a/20405684/1781718

Comments