android control side sliding navigationview

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:theme="@style/AppTheme"
        app:headerLayout="@layout/navigation_head"
        app:menu="@menu/navigation_menu"
<pre>    />
 
 

Be sure to add the android:layout_gravity="left" attribute 


1,android:theme="@style/AppTheme" 

Set to be the same as the theme style, apptheme is its own style, you can set:

<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/windowBackground</item>

 2,app:headerLayout="@layout/navigation_head"

Head, get the head: headview = navigationView.getHeaderView(0)

Some people customize the header file and write the item into it, so that they can use headview. It is also possible to find to get the control of the head.


3, app:menu="@menu/navigation_menu"

item option, set the background color, if you do not need to change, you can set @null

app:itemTextColor: Used to set the color selector of menu item in Nav.

There are also some attributes: Same as itemTextColor usage, specify a color selector to achieve different color effects.
app:itemIconTint:
app:itemBackground:





Guess you like

Origin blog.csdn.net/l331258747/article/details/53080051