簡體   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