[英]FragmentContainerView as the navigation view in DrawerLayout
I have a fragment that I sometimes want to display as a full screen and sometimes as the contents of the burger menu.我有一个片段,有时想全屏显示,有时想显示为汉堡菜单的内容。
I have setup an activity with a burger menu like so:我已经设置了一个带有汉堡菜单的活动,如下所示:
<?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>
The WhateverFragment
has a RecyclerView and in each item I add a OnClickListener
. WhateverFragment
有一个 RecyclerView 并且在每个项目中我添加了一个OnClickListener
。 When presented as a fragment of full screen activity that listener is invoked.当作为全屏活动的片段呈现时,将调用该侦听器。
However, when i tap anywhere in my 'drawer' then it simply closes and my onclicklistener is not invoked in my fragment.但是,当我点击“抽屉”中的任何位置时,它就会关闭,并且不会在我的片段中调用我的 onclicklistener。
What am I missing?我错过了什么?
As per @Mike-M:根据@Mike-M:
The drawer should be listed last within the <DrawerLayout>
tags in order for it to receive touch events properly.抽屉应该在<DrawerLayout>
标签中最后列出,以便它正确接收触摸事件。 That is, move your <androidx.fragment.app.FragmentContainerView>
to after everything in activity UI here
.也就是说,将您的<androidx.fragment.app.FragmentContainerView>
移动到activity UI here
中的所有内容之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.