1 回答

TA貢獻1779條經驗 獲得超6個贊
在BottomActivity中將此添加到您的onCreate中:
NavigationView nav_view;
nav_view = findViewById(R.id.nav_view); //select nav_view from activity_drawer_layout
nav_view.setNavigationItemSelectedListener(this);
在activity_drawer_layout.xml中,將NavigationView放在DrawerLayout的結束標記上方。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="@+id/DrawerLayout">
<include
android:id="@+id/include"
layout="@layout/app_bar_nav_drawer"
android:layout_width="0dp"
android:layout_height="0dp" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="673dp"
android:padding="16dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/age"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:layout_constraintBottom_toBottomOf="@+id/nav_header" />
<include
android:id="@+id/include"
layout="@layout/app_bar_nav_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:headerLayout="@layout/nav_header_nav_drawer"
app:menu="@menu/activity_nav_drawer_drawer" />
</android.support.v4.widget.DrawerLayout>
添加回答
舉報