我尝试了很多变体来创建全屏对话框,但我做不到。我需要这样的东西,有两个按钮:
最佳答案
如果您真的想要一个全屏对话框,只需扩展 Dialog
类并添加一些调整即可。 (您也可以在不扩展任何内容的情况下完成此操作,但我认为您可能希望将所有内容保存在一个地方)
在你的构造函数中你需要设置样式(为了你的 Material 外观,或者它可以是一个空的样式标签):
super(context, R.style.DialogStyle);
您还需要设置 View :(这是您定义这两个按钮的位置/内容的地方)
setContentView(R.layout.dialog_view);
最后,您可能还需要修改窗口布局参数:
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
我在我测试过的设备上发现,设置样式是最重要的。
*编辑*
为了更清楚一点,您有两个选择:
public class MyDialog extends Dialog {
public MyDialog(Context context) {
super(context, R.style.YourStyle);
setContentView(R.layout.dialog_view);
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); //Optional
//Any other code you want in your constructor
}
}
然后当你想展示它的时候:
//Inside your activity
MyDialog dialog = new MyDialog(this); //Assuming you are in an activity 'this' is your context
dialog.show();
或者你可以这样做:
Dialog normalDialog = new Dialog(this, R.style.YourStyle);
normalDialog.setContentView(R.layout.dialog_view);
normalDialog.show();
关于android - 如何制作 Material Design 全屏对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32017068/