Android删除导航菜单项突出显示

时间:2016-07-05 14:55:07

标签: 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>

4 个答案:

答案 0 :(得分:13)

也许你可以使用这样的东西,
为了防止项目在点击时更改其颜色,您可以尝试更改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

了解详情

答案 1 :(得分:3)

因此colorControlHighlight会根据<style name="Drawer" parent="Theme.AppCompat.Light"> <item name="colorControlHighlight">#0000</item> </style> 属性突出显示。您可以为抽屉创建主题并使其透明:

<android.support.design.widget.NavigationView
    ...
    android:theme="@style/Drawer" />
> dput(foo)
structure(list(Vehicle.ID2 = c("3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588", "3361-588", "3361-588", 
"3361-588", "3361-588", "3361-588", "3361-588"), Frame.ID = 2110:2146, 
    State = c("Following", "Following", "Following", "Following", 
    "Following", "Following", "Following", "Following", "Following", 
    "Approaching-fastveh", "Approaching-fastveh", "Approaching-fastveh", 
    "Following", "Following", "Following", "Following", "Following", 
    "Following", "Following", "Following", "Following", "Following", 
    "Following", "Following", "Following", "Following", "Following", 
    "Following", "Following", "Following", "Approaching-fastveh", 
    "Approaching-fastveh", "Approaching-fastveh", "Approaching-fastveh", 
    "Approaching-fastveh", "Approaching-fastveh", "Approaching-fastveh"
    )), .Names = c("Vehicle.ID2", "Frame.ID", "State"), class = c("tbl_df", 
"data.frame"), row.names = c(NA, -37L))

答案 2 :(得分:0)

尝试在您的活动中实施NavigationView.OnNavigationItemSelectedListener 并强制return false

override fun onNavigationItemSelected(item: MenuItem): Boolean {
    // Handle navigation view item clicks here.
     when (item.itemId) { 
      }

return false

医生说:

/**
 * Called when an item in the navigation menu is selected.
 *
 * @param item The selected item
 *
 * @return true to display the item as the selected item
 */
public boolean onNavigationItemSelected(@NonNull MenuItem item);

答案 3 :(得分:0)

您必须在 drawer_items.xml 中将所有状态设置为 false

<?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="false" />
  <item android:drawable="@color/grey" android:state_selected="false" />
  <item android:drawable="@color/grey" android:state_focused="false"  />
  <item android:drawable="@color/grey" android:state_pressed="false" />
  <item android:drawable="@color/grey" android:state_checked="false" />
  <item android:drawable="@color/grey" />
</selector>

尽管回答这个问题为时已晚,但是搜索相同问题的人可能会发现它很有用。让我知道这个答案是否对您有帮助。