android-studio - Android Drawer Menu 自定义样式
高洛峰
高洛峰 2017-04-17 15:37:01
0
2
390

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>
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
Ty80

The menu generated by the system by default is a default view implementation, which can only add menu items and cannot customize the layout.
You need to delete the menu.xml generated by the system, create a new layout file in the layout directory, and replace it with your own view layout.

Then includeyour own 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>

I am a picture ↓

PHPzhong

The xml of the menu is responsible for the content

style is managed by the view that displays the menu, such as NavigationView's android.support.design:itemTextAppearance

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!