活动对话框在外部触摸时关闭

活动对话框在外部触摸时关闭

本文介绍了防止 Android 活动对话框在外部触摸时关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Theme.Dialog 样式的活动,因此它是另一个活动的浮动窗口.但是,当我在对话框窗口外(在后台活动上)单击时,对话框将关闭.我怎样才能阻止这种行为?

I have an activity that is using the Theme.Dialog style such that it is a floating window over another activity. However, when I click outside the dialog window (on the background activity), the dialog closes. How can I stop this behaviour?

推荐答案

这可以帮助您.这是一种处理触摸外部事件的方法:

This could help you. It is a way to handle the touch outside event:

如何在窗口外触摸时取消以活动为主题的对话框?

通过捕捉事件而不做任何事情,我认为您可以防止关闭.但奇怪的是,您的活动对话框的默认行为应该是在您触摸外部时自行关闭.

By catching the event and doing nothing, I think you can prevent the closing. But what is strange though, is that the default behavior of your activity dialog should be not to close itself when you touch outside.

(PS:代码使用的是WindowManager.LayoutParams)

(PS: the code uses WindowManager.LayoutParams)

这篇关于防止 Android 活动对话框在外部触摸时关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:46