在不使用主题修改器的情况下以对话框形式启动 Android 活动
我想以对话框的形式启动一个活动,这可以简单地通过以下方式完成:
<activity android:theme="@android:style/Theme.Dialog">
但我想控制对话框,所以我必须以编程方式完成。基本上我想修改对话框的这个属性:
mCanceledOnTouchOutside = true
这将使对话框在触摸其边界之外时自行取消。 (基本上我想复制弹出行为)。问题是我不能简单地创建一个对话框并设置它的布局,因为我需要调用活动(初始化数据集)
这可能吗?
I want to start an activity as a dialog, which can be simply done by:
<activity android:theme="@android:style/Theme.Dialog">
But I want to do control the dialog, so I've to do it programmatically. Basically I want to modify this property of dialog:
mCanceledOnTouchOutside = true
This will make the dialog cancel itself when touched outside of it's bounds. (Basically I want to replicate the popup behavior). The issue is I can't simply create a dialog and set it's layout since I need a call to activity (to initialized datasets)
Is this possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从那以后这并没有真正实现,因为活动不是对话框。通过设置主题,您所做的就是使活动直观地使用对话框的主题。它仍然是一个活动,但是,将是所有正常活动的行为。换句话说,不存在具有关联行为的 Dialog 对象。
This doesn't really make since, because an activity is not a dialog. By setting the theme, all you are doing is causing the activity to visually use the theme of a dialog. It is still an activity, however, will all of the normal activity behavior. In other words, there is no Dialog object with its associated behavior.
我只是想在我的对话框样式活动之一上重现此 cancelOutside 对话框行为。为此,我提取了处理触摸事件的对话框源代码(Dialog.java):
我将其复制粘贴到我的对话框样式活动中并更改了一些小东西:
它工作正常!
I just wanted to reproduce this cancelOutside Dialog behavior on one of my Dialog style Activity. For this I extracted the Dialog source code (Dialog.java) handling the touch event:
I Copy paste it in my Dialog style activity and changed small things:
It works fine!
您可以在
values/styles.xml
文件(或任何您想要的名称)中定义扩展Theme.Dialog
的您自己的样式。查看 http://developer.android.com/guide/topics/ ui/themes.html#继承。我不确定这是否有效,但也许可以尝试以下方法:
You can define your own style that extends
Theme.Dialog
in avalues/styles.xml
file (or whatever you want to call it). Check out http://developer.android.com/guide/topics/ui/themes.html#Inheritance.I'm not sure if this will work, but maybe try something like: