作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
导航 View 有问题,在菜单项上单击我希望背景不改变颜色。
这是我的抽屉布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:orientation="vertical">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:background="@color/blue_dark"
app:itemTextAppearance="@style/NavDrawerTextStyle"
app:itemBackground="@drawable/nav_menu_background_selector"
app:itemTextColor="@color/nav_menu_color_change"
android:theme="@style/NavigationDrawerStyle"
android:id="@+id/nav_view"
android:paddingLeft="47px"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" >
<View
android:layout_gravity="right"
android:background="@color/color_lite_green"
android:layout_width="2dp"
android:layout_height="match_parent"></View>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
我试过使用和不使用选择器。这是我的选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/blue_dark" />
<item android:state_pressed="false" android:drawable="@color/blue_dark" />
</selector>
当我使用与菜单项背景相同的背景制作这样的选择器时,单击它会出现某种阴影。当我不使用选择器时,单击菜单项时也会发生同样的事情。我只想在菜单上单击不要更改背景。我怎样才能做到这一点?我已经尝试过类似问题的解决方案,但到目前为止没有任何效果。
谢谢
最佳答案
我遇到了同样的问题,有 2 个解决方案,在“onNavigationItemSelected(MenuItem item)”中为每个项目添加“item.setCheckable(true);” ,或在菜单项布局中添加“android:checkable="true"”。
关于android - 导航 View : I want on menu click, 菜单项不改变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53317660/
我是一名优秀的程序员,十分优秀!