2016-07-05 79 views
1

當您單擊我的導航抽屜中的菜單項時,它會變得稍暗並保持這種狀態,直到單擊另一個項目。我試圖讓它保持相同的顏色,不管它處於什麼狀態。Android刪除導航菜單項突出

它是否是某種疊加?我想我已經在drawer_items.xml中覆蓋了所有可能的狀態。
如何防止此行爲?

activity_main.xml中

<android.support.design.widget.NavigationView 
    . 
    . 
    android:background="@drawable/drawer_items" 
    . 
    app:menu="@menu/activity_main_drawer" /> 

drawer_items.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@color/grey" android:state_activated="true" /> 
    <item android:drawable="@color/grey" android:state_selected="true" /> 
    <item android:drawable="@color/grey" android:state_focused="true" /> 
    <item android:drawable="@color/grey" android:state_pressed="true" /> 
    <item android:drawable="@color/grey" android:state_checked="true" /> 
    <item android:drawable="@color/grey" /> 
</selector> 

activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <group android:checkableBehavior="single" 
      android:id="@+id/arbitrary_id_1"> 
     <item 
     android:id="@+id/nav_refresh" 
     android:icon="@drawable/ic_refresh_24dp" 
     android:title="Try Again/Refresh" /> 
    </group> 

    <group android:checkableBehavior="single" 
      android:id="@+id/arbitrary_id_2"> 
     <item 
     android:id="@+id/nav_back" 
     android:icon="@drawable/ic_fast_rewind_24dp" 
     android:title="Go Back" /> 
    </group> 

    <group android:checkableBehavior="single" 
      android:id="@+id/arbitrary_id_3"> 
     <item 
     android:id="@+id/nav_3" /> 
    </group> 

</menu> 
+0

發表您的'activity_main_drawer' – tachyonflux

+0

也許您的問題來源於代碼的活動,而不是從XML,你可以發佈您的代碼? – JJ86

回答

1

也許你可以使用這樣的事情,
防止項目從點擊時改變其顏色,你可以嘗試在activity_main_drawer.xml改變:

<group android:checkableBehavior="single"> 

<group android:checkableBehavior="none"> 

或者你也可以做到這一點的方法:

<group android:checkableBehavior="single"> 
    ... 
    <item 
     android:id="@+id/item_one" 
     android:icon="@drawable/ic_item_one" 
     android:title="Item One"/> 
    ... 
    </group> 

要:

<item> 
    <menu> 
     ... 
     <item 
     android:id="@+id/item_one" 
     android:icon="@drawable/ic_item_one" 
     android:title="Item One"/> 
     ... 
    </menu> 
    </item> 

更多的Menus

2

所以NavigationView是基於colorControlHighlight性能突出。你可以爲你的抽屜裏創建一個主題,使之透明:

<style name="Drawer" parent="Theme.AppCompat.Light"> 
    <item name="colorControlHighlight">#0000</item> 
</style> 

<android.support.design.widget.NavigationView 
    ... 
    android:theme="@style/Drawer" />