[英]Changing color of navigation drawer item before clicking it
我正在更改導航抽屜中所選項目的顏色,並且通過以下代碼可以正常工作
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextAppearance="@style/NavDrawerTextStyle"
app:menu="@menu/activity_main_drawer"
app:itemTextColor="@color/nav_item_color"
android:background="#000000"/>
</android.support.v4.widget.DrawerLayout>
以下是為我做花招的代碼行
app:itemTextColor="@color/nav_item_color"
顏色目錄中的xml代碼
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#81DDFF" android:state_checked="true" style="@style/NavDrawerTextStyle"/>
<item android:color="#FFFFFF" style="@style/NavDrawerTextStyle"/>
</selector>
現在,對我來說,問題是,當抽屜第一次打開時,我想更改導航抽屜的第一項的顏色(在單擊之前,因為存在與第一項相對應的屏幕)。
換句話說,如何從活動類中更改單個導航抽屜項目的顏色? 謝謝
這是抽屜第一次打開時的屏幕截圖,我希望登錄項的顏色為淺藍色
單擊登錄項並再次打開抽屜時
您可以手動選擇
navigationView.getMenu().getItem(0).setChecked(true);
或者你可以使用
navigationView.setCheckedItem(menuItemid);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.