Dialogs and Popups in Android
Asked Answered
K

1

12

The Android design documentation in http://developer.android.com/design/building-blocks/dialogs.html makes a clear differentiation between Dialogs, Alerts, Popups and Toasts. It also recommends the implementation of Dialogs by means of the DialogFragment class and Toasts by means of the Toast class. However it's not clear to me whether Popups should be implemented with PopupWindow or with DialogFragment.

I know that DialogFragments usually come with Ok/Cancel buttons and that the location of PopupWindows can be defined, but:

Kinin answered 29/8, 2013 at 23:7 Comment(1)
Ok, according to dialogs.html, they're recommending the use of DialogFragmenteven for windows such as list_dialog that doesn't have buttons. Besides, I guess that the fact of being based on Fragments eases it's addition to the BackStack, whereas I'm not clear how would I do that with a PopupWindow. Therefore, I'm going for the DialogFragment approach, although I would still appreciate some deeper details on the comparison of both classes.Kinin
H
2

If you want dialog as shown in the link, just make them by making custom dialog as mentioned below:

Make a dialog object:

Dialog dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);

Set custom view to this dialog:

show_dialog(){
    dialog.setContentView(R.layout.custom_dialog);//your custom dialog layout.
}

Your custom layout should be like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id="@+id/custom_dialog_first_rl"
    android:background="@android:color/black">
<!-- write code for rest of your UI here -->
</RelativeLayout>

Now set alpha for your first relative layout in show_dialog() like this:

show_dialog(){
    dialog.setContentView(R.layout.custom_dialog);//your custom dialog layout.
    RelativeLayout custom_dialog_first_rl=(RelativeLayout)dialog.findViewById(R.id.custom_dialog_first_rl);
        custom_dialog_first_rl.getBackground().setAlpha(170);
}

Call show_dialog() where you wanna show this dialog

Hurried answered 1/9, 2014 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.