【发布时间】:2020-05-14 19:19:52
【问题描述】:
我正在制作一个简单的导航抽屉,但是我的 header.xml 没有显示在我的 navigation_drawer.xml 中。
我仔细检查了一切,看起来还不错。我是否错过了什么或做错了什么?
谢谢!
activity_navigation_drawer.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
android:background="@color/black"
tools:context=".NavigationDrawer"
android:id="@+id/drawer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="@color/black"/>
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/navigationView"
app:menu="@menu/menu_item"
app:headerLayout="@layout/header"
android:background="@color/seekbar_container_color"/>
</androidx.drawerlayout.widget.DrawerLayout>
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/activated_btn_color">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/brightness_icon"
android:layout_gravity="center"
android:tint="@color/white"
android:layout_marginTop="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_txt"
android:textSize="20sp"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_marginTop="3dp"/>
</LinearLayout>
styles.xml sn-p:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
【问题讨论】:
标签: android xml android-layout