我做了一个Navigation Drawer
。我在header.xml
中添加了ImageView
,但它没有显示在屏幕上。
<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"
app:menu="@menu/menu_main_activity">
</com.google.android.material.navigation.NavigationView>
header.xml
<androidx.constraintlayout.widget.ConstraintLayout 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="200dp"
android:background="@color/colorPrimaryDark">
<ImageView
android:id="@+id/iv_logo"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="32dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_menu"
android:contentDescription="@string/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
style="@style/Text"
android:text="@string/slogan"
app:layout_constraintStart_toStartOf="@+id/iv_logo"
app:layout_constraintTop_toBottomOf="@+id/iv_logo" />
</androidx.constraintlayout.widget.ConstraintLayout>
只需替换:
tools:src="@drawable/ic_menu"
跟
android:src="@drawable/ic_menu"