简体   繁体   English

导航抽屉中具有不同背景颜色的每个菜单项

[英]Navigation Drawer each menu item with different background color

嗨,大家好,我是android的新手,我刚刚开始学习android.so,我在应用中实现了导航抽屉,但是在导航抽屉中我已经使用menu.xml添加了菜单

you can always create your custom layout instead of using menu so you can design it in your way for your navigation drawer. 您始终可以创建自定义布局,而不使用菜单,因此可以按照自己的方式为导航抽屉设计布局。 for example. 例如。

Navigation View 导航视图

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <include layout="@layout/lay_drawer_menu" />

    </LinearLayout>
</ScrollView>
</android.support.design.widget.NavigationView>

lay_drawer_menu.xml lay_drawer_menu.xml

<TextView
    android:id="@+id/txt1"
     android:textcolor = "whatever you want"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="onClick"
    android:text="Activities" />

<TextView
    android:id="@+id/txt2"
     android:textcolor = "whatever you want"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="onClick"
    android:text="Add Detail"
    android:textColor="@android:color/black" />

Activity 活动

@Override public void onClick(View view) { @Override public void onClick(View view){

        switch (view.getId()) {
            case R.id.txt1: {
                drawerLayout.closeDrawers();

               //your code.

            }
            break;
           case R.id.txt2: {
                drawerLayout.closeDrawers();

               //your code.

            }
            break;

        }

    }

hope this will help. 希望这会有所帮助。

Well, you can go through below link to create a custom Navigation Drawer on your own.You can customize it to what ever you want. 好了,您可以通过下面的链接自行创建自定义导航抽屉,也可以根据需要进行自定义。 Custom Navigation Drawer 自定义导航抽屉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM