在Swift中,我们可以使用一个名为“ SideMenu”的库在SideMenu上显示viewController。
现在,我正在使用Android进行编码。我想在NavigationView中显示活动,我们只能显示一个Menu或标题。我无法在NavigationView上显示活动或片段。
您可以帮我解决这个问题吗?
Android应用程序可以一次显示一个活动(最近已更改,但在您的情况下仍然如此)。在您的情况下,应为View或Fragment充气。只需将您的布局或片段放在其中NavigationView
:
<?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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer">
<TextView
android:text="Custom View"
android:layout_gravity="center"
android:background="#ff0000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
NavigationView
扩展FrameLayout,以便如果您要膨胀菜单,它将重叠。因此,您可能要删除:
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句