如何从透明覆盖片段中禁用背景 activity
how to disable background activity from transparent overlay fragment
我在 activity 上创建了透明片段叠加教程,我想禁用透明片段下方显示的背景 activity 的触摸事件。因此用户无法触摸 activity 中的任何内容,只能使用片段帮助教程。
提前致谢
如果您在设置为全屏的 activity 上使用片段,即 match_parent
。然后在 fragments root 布局中你可以设置一个属性 android:clickable="true"
来消耗点击事件。默认情况下,诸如 RelativeLayout 、 LinearLayout 等布局不会消耗点击事件。 Button 和 TextView 等其他视图默认启用此功能。
在您的覆盖片段中。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true">
</RelativeLayout>
或者直接通过id找到fragment的父view...然后在上面设置onClick监听器..
完成。
我在 activity 上创建了透明片段叠加教程,我想禁用透明片段下方显示的背景 activity 的触摸事件。因此用户无法触摸 activity 中的任何内容,只能使用片段帮助教程。
提前致谢
如果您在设置为全屏的 activity 上使用片段,即 match_parent
。然后在 fragments root 布局中你可以设置一个属性 android:clickable="true"
来消耗点击事件。默认情况下,诸如 RelativeLayout 、 LinearLayout 等布局不会消耗点击事件。 Button 和 TextView 等其他视图默认启用此功能。
在您的覆盖片段中。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true">
</RelativeLayout>
或者直接通过id找到fragment的父view...然后在上面设置onClick监听器.. 完成。