【问题标题】:FragmentContainerView as the navigation view in DrawerLayoutFragmentContainerView 作为 DrawerLayout 中的导航视图
【发布时间】: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 不会在我的片段中调用。

我错过了什么?

【问题讨论】:

  • 抽屉应在&lt;DrawerLayout&gt; 标签中最后列出,以便它正确接收触摸事件。也就是说,将您的&lt;androidx.fragment.app.FragmentContainerView&gt; 移动到activity UI here 中的所有内容之后。
  • @迈克M。这行得通!非常感谢:)如果您将此添加为答案,我会接受
  • 没问题。不过我很好。 :-) 没什么大不了的。请随意完成此操作,但您愿意。不过谢谢。我很感激这个提议。真高兴你做到了。干杯!

标签: android kotlin navigation-drawer drawerlayout


【解决方案1】:

根据@Mike-M:

抽屉应在&lt;DrawerLayout&gt; 标签中最后列出,以便它正确接收触摸事件。也就是说,将您的&lt;androidx.fragment.app.FragmentContainerView&gt; 移动到activity UI here 中的所有内容之后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2023-01-19
    • 1970-01-01
    • 2010-12-05
    • 2020-06-13
    • 2019-09-19
    • 1970-01-01
    相关资源
    最近更新 更多