http://developer.android.com/design/building-blocks/dialogs.html 中的 Android 设计文档明确区分对话框、警报、弹出窗口和 toast 。它还建议通过 DialogFragment
类实现 Dialogs,通过 Toast
类实现Toasts。但是我不清楚 Popups 应该用 PopupWindow
还是用 DialogFragment
来实现。
我知道 DialogFragments
通常带有确定/取消按钮,并且可以定义 PopupWindows
的位置,但是:
- 这些细微差别是使用其中一种的唯一论据吗?
DialogFragment
是否是PopupWindow
的后继者,但在某些时候会被弃用?- 根据https://stackoverflow.com/a/15165554/2482894中的答案,PopupWindow 是“Limited to a few templates”,但我在类文档中找不到任何对有限数量模板的引用。
- 那么,最后,您将如何实现像这样的弹出窗口 http://developer.android.com/design/media/dialogs_popups_example.png为什么?
最佳答案
如果你想要链接中显示的对话框,只需按照下面提到的制作自定义对话框来制作它们:
创建一个对话框对象:
Dialog dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);
为此对话框设置自定义 View :
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()
你想显示这个对话框的地方
关于android - Android 中的对话框和弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18522362/