首页 > Android Drawer Menu 自定义样式

Android Drawer Menu 自定义样式

Android Drawer的应用,但是不知道怎么修改Menu的样式,google了半天,也没找到解决办法,希望sf的朋友!们能指点迷津,谢谢啦!(注:第一张是设计图,第二张是我现在做出来的现状)

这是代码白色菜单的代码部分:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_user_number"
            android:icon="@drawable/nav_user"
            android:title="@string/user_number"/>
        <item
            android:id="@+id/nav_message"
            android:icon="@drawable/nav_message"
            android:title="@string/message"/>
        <item
            android:id="@+id/nav_setting"
            android:icon="@drawable/nav_setting"
            android:title="@string/setting"/>
        <item
            android:id="@+id/nav_about"
            android:icon="@drawable/nav_about"
            android:title="@string/about"/>
    </group>

</menu>

menu的xml是負責內容的

style是顯示menu的那個view在管理, 比如NavigationView的android.support.design:itemTextAppearance


系统默认生成的menu是一个默认的view实现,只能添加菜单项,不能自定义布局。
你需要把系统生成的menu.xml删掉,在layout目录下新建一个布局文件,换成自己的view布局。

然后 include自己的layout
已省略部分代码

<android.support.v4.widget.DrawerLayout>

    //侧滑菜单主框架
    <include
        layout="@layout/app_bar_nav"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    //菜单部分
    <LinearLayout
        android:layout_width="@dimen/nav_width"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:orientation="vertical"
        android:layout_gravity="start">

        //头部头像部分
        <include
            layout="@layout/nav_header_nav"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

        //你自定义的菜单布局,具体里面你随意实现你自己需要的内容
        <include
            layout="@layout/nav_menu"
            android:layout_width="match_parent"
            android:layout_weight="3"
            android:layout_height="0dp"
            />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

我是图 ↓

【热门文章】
【热门文章】