gpt4 book ai didi

android - 导航 View : I want on menu click, 菜单项不改变背景

转载 作者:太空狗 更新时间:2023-10-29 14:37:43 25 4
gpt4 key购买 nike

导航 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com