繁体   English   中英

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

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

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

您始终可以创建自定义布局,而不使用菜单,因此可以按照自己的方式为导航抽屉设计布局。 例如。

导航视图

<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

<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" />

活动

@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;

        }

    }

希望这会有所帮助。

好了,您可以通过下面的链接自行创建自定义导航抽屉,也可以根据需要进行自定义。 自定义导航抽屉

暂无
暂无

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

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