问题描述
当我在另一个片段上显示一个片段(带有 #77000000
背景的全屏)时,我的主片段仍然对点击做出反应(我们可以点击一个按钮即使我们没有看到它).
When I'm showing one fragment (which is full screen with #77000000
background) over another fragment (let's call it main), my main fragment still reacts to clicks (we can click a button even if we don't see it).
问题:如何防止点击第一个(主要)片段?
Question: how to prevent clicks on first (main) fragment?
编辑
不幸的是,我不能只隐藏主片段,因为我在第二个片段上使用透明背景(因此,用户可以看到后面的内容).
Unfortunately, I can't just hide main fragment, because I'm using transparent background on second fragment (so, user can see what located behind).
推荐答案
将第二个片段视图的 clickable
属性设置为 true.视图将捕获事件,以便它不会传递给主片段.因此,如果第二个片段的视图是布局,则代码如下:
Set clickable
property on the second fragment's view to true. The view will catch the event so that it will not be passed to the main fragment. So if the second fragment's view is a layout, this would be the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
这篇关于另一个片段问题的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!