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:

4

1 回答 1

2

如果您想要链接中显示的对话框,只需通过制作自定义对话框来制作它们,如下所述:

制作一个对话框对象:

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

将自定义视图设置为此对话框:

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

您的自定义布局应该是这样的:

<?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>

现在在 show_dialog() 中为您的第一个相对布局设置 alpha,如下所示:

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);
}

show_dialog()在您想显示此对话框的位置调用

于 2014-09-01T11:39:55.110 回答