Android 对话框:在后台切换活动
我可以在对话框的背景中启动活动吗 我想要的是:活动启动对话框,对话框交换后台显示的活动。对话框不会被取消 我认为只有当对话也是一种活动时,才能做到这一点 我所想的是一个解决方案:Android 对话框:在后台切换活动,android,android-activity,dialog,Android,Android Activity,Dialog,我可以在对话框的背景中启动活动吗 我想要的是:活动启动对话框,对话框交换后台显示的活动。对话框不会被取消 我认为只有当对话也是一种活动时,才能做到这一点 我所想的是一个解决方案: 我从DialogActivity向Act 1发送本地广播 第一幕开始第二幕,然后自我毁灭 问题:第2幕将显示在DialogActivity前面。我想在后面换一下 这可能吗?遵循以下几点制定有效的解决方案: 要使对话框的窗口显示在所有应用程序窗口的顶部,请将其窗口类型设置为“系统窗口” 使用应用程序上下文创建对话框。如果
这可能吗?遵循以下几点制定有效的解决方案:
// This is a button click handler.
public void launchDialog(final View v) {
// Create the dialog with application context
AlertDialog dialog = new AlertDialog.Builder(getApplicationContext())
.setTitle("Title")
.setMessage("This is dialog")
.create();
// Set the window type as system window
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
// Demonstrates the activity change behind the dialog.
v.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(v.getContext(), MyActivity2.class);
startActivity(intent);
finish();
}
}, 3000);
}
请记住在清单中设置使用系统窗口的权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
非常有魅力!我把它变成了一个常规对话框,并添加了自己的复杂布局。谢谢!