【发布时间】:2022-11-14 12:51:22
【问题描述】:
我有一个片段,有时我想显示为全屏,有时显示为汉堡菜单的内容。
我已经设置了一个带有汉堡菜单的活动,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ui.SomeActivity"
>
<!-- tools:openDrawer="left"-->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/my_menu_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.myapplication.ui.WhateverFragment"
android:background="@color/someBackgroundColor"
tools:layout="@layout/brand_feed_fragment"
android:clickable="true" />
<!-- clickable had no effect actually -->
.... activity UI here
</androidx.drawerlayout.widget.DrawerLayout>
WhateverFragment 有一个 RecyclerView,我在每个项目中添加一个 OnClickListener。当呈现为全屏活动的片段时,将调用该侦听器。
但是,当我点击“抽屉”中的任何位置时,它会简单地关闭,并且我的 onclicklistener 不会在我的片段中调用。
我错过了什么?
【问题讨论】:
-
抽屉应在
<DrawerLayout>标签中最后列出,以便它正确接收触摸事件。也就是说,将您的<androidx.fragment.app.FragmentContainerView>移动到activity UI here中的所有内容之后。 -
@迈克M。这行得通!非常感谢:)如果您将此添加为答案,我会接受
-
没问题。不过我很好。 :-) 没什么大不了的。请随意完成此操作,但您愿意。不过谢谢。我很感激这个提议。真高兴你做到了。干杯!
标签: android kotlin navigation-drawer drawerlayout