Android Activity 作为对话框 [英] Android Activity as a dialog

查看:34
本文介绍了Android Activity 作为对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 whereActity 的活动,它也有子对话框.现在,我想将此活动显示为另一个活动的对话框.

I have an Activity named whereActity which has child dialogs as well. Now, I want to display this activity as a dialog for another activity.

我该怎么做?

推荐答案

要将活动作为对话框启动,我在 AndroidManifest.xml 中这样定义:

To start activity as dialog I defined it like this in AndroidManifest.xml:

<activity android:theme="@android:style/Theme.Dialog" />

在您的 activity 标签中使用此属性,以避免您的 Dialog 出现在最近使用的应用程序列表中

Use this property inside your activity tag to avoid that your Dialog appears in the recently used apps list

android:excludeFromRecents="true"

如果你想在用户点击对话框外时阻止你的对话框/活动被破坏:

If you want to stop your dialog / activity from being destroyed when the user clicks outside of the dialog:

在您的 Activity 中的 setContentView() 之后使用:

After setContentView() in your Activity use:

this.setFinishOnTouchOutside(false);

现在,当我调用 startActivity() 时,它显示为一个对话框,当用户按下后退按钮时会显示上一个活动.

Now when I call startActivity() it displays as a dialog, with the previous activity shown when the user presses the back button.

请注意,如果您使用 ActionBarActivity(或 AppCompat 主题),则需要改用 @style/Theme.AppCompat.Dialog.

Note that if you are using ActionBarActivity (or AppCompat theme), you'll need to use @style/Theme.AppCompat.Dialog instead.

这篇关于Android Activity 作为对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆