NavigationView的使用
生活随笔
收集整理的這篇文章主要介紹了
NavigationView的使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
新建一個(gè)抽屜活動(dòng)后,我們可以看到主界面的布局文件是這樣的
<?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:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"tools:openDrawer="start"><includelayout="@layout/app_bar_main"android:layout_width="match_parent"android:layout_height="match_parent" /><android.support.design.widget.NavigationViewandroid: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" /></android.support.v4.widget.DrawerLayout>其實(shí)這里的NavigationView就是左邊抽屜拉出來后的布局了~可以看到它有兩個(gè)屬性app:headerLayout和app:menu其實(shí)這兩個(gè)屬性后面就分別是上圖中藍(lán)色背景部分的抽屜頭和下面的菜單。要對(duì)其編輯也很簡(jiǎn)單,進(jìn)入ID對(duì)應(yīng)的布局修改即可。
操作1:
前面提到的獲取不到控件的方法,可以在onCreate方法中這樣來獲取
View headerLayout = navigationView.inflateHeaderView(R.layout.nav_header_main);tv_nav_user = (TextView)headerLayout.findViewById(R.id.tv_nav_username); 通過查看谷歌官方開發(fā)文檔我們還可以發(fā)現(xiàn)幾個(gè)方法
http://developer.android.com/reference/android/support/design/widget/NavigationView.html
這些方法都是對(duì)抽屜布局上的菜單和頭布局進(jìn)行操作時(shí)可以使用的。同時(shí)注意
總結(jié)
以上是生活随笔為你收集整理的NavigationView的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android vector Path
- 下一篇: SharedPreference.Edi