如何在不更改当前正在运行的 Activity 的布局文件的情况下,在当前运行的 Activity 上添加具有新布局的新对话框。我无法添加新 Activity ,因为在显示新对话框时旧 Activity 应保持 Activity 状态。
最佳答案
这是一个开始创建 Dialog
并向其应用布局文件的小 fragment 。
// create an instance of Dialog
Dialog dialog= new Dialog(c, R.style.CustDialog);
//inflate a layout
LayoutInflater inflater = this.getLayoutInflater();
View root = inflater.inflate(R.layout.custom_alert, null);
// set the layout for the Dialog
dialog.setContentView(root);
如果您阅读 Dialog Docs它提供了您可以使用的不同方法。
注意文档说
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:
因此,您可能需要查看 AlertDialog您可以在 SO 或 Google 上找到大量示例。
This answer给出了创建自定义 Dialog
类的示例。
关于android - 在当前运行的 Activity 上添加一个具有新布局的新对话框,而不更改当前运行的 Activity 的布局文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775494/