NavigationView

 
一、 用途:NavigationView一般和DrawerLayout一起配合使用。
二、引入原因:当我们使用
DrawerLayout的时候,我们完全可以将content和menu
都写在一个XML中,但是引入
NavigationView后,就可以简化我们的XML
三、用法:
DrawerLayout的布局完全不变,将menu的跟布局改成navigationView,
menu拆分成
头部(
headerLayout
)和内容(menu)部分,通过以下属性引入即可
xmlns:app="http://schemas.android.com/apk/res-auto"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
四、eg
<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"
   >
<!--content-->
    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

<!--menu -->
<android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" android:background="@color/white" app:headerLayout="@layout/nav_header_main" app:itemBackground="@drawable/nav_item_bg" app:itemTextAppearance="@style/TextStyle.Primary" android:visibility="gone" app:itemTextColor="@color/textColorPrimary" app:menu="@menu/activity_main_drawer" /></android.support.v4.widget.DrawerLayout>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值