android tab selected color,android - Selected tab's color in Bottom Navigation View - Stack Overflow

在Android开发中,遇到一个问题:尝试为BottomNavigationView设置不同颜色来区分选中和未选中的tab,但使用colorselector资源文件的state_selected不起作用。尝试了添加state_focused和state_enabled属性,以及明确设置state_selected为false,都无法实现预期效果。布局代码和colorselector资源文件已给出,寻求解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm adding a BottomNavigationView to a project, and I would like to have a different text (and icon tint) color for the selected tab (to achieve greying out non-selected tabs effect). Using a different color with android:state_selected="true" in a color selector resource file doesn't seem to work. I also tried having additional item entries with android:state_focused="true" or android:state_enabled="true", no effect unfortunately. Also tried setting the state_selected attribute to false (explicitly) for the default (non-selected) color, with no luck.

Here is how I add the view to my layout:

android:id="@+id/bottom_navigation"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

app:itemBackground="@color/silver"

app:itemIconTint="@color/bnv_tab_item_foreground"

app:itemTextColor="@color/bnv_tab_item_foreground"

app:menu="@menu/bottom_nav_bar_menu" />

Here is my color selector (bnv_tab_item_foreground.xml):

And my menu resource (bottom_nav_bar_menu.xml):

android:id="@+id/action_home"

android:icon="@drawable/ic_local_taxi_black_24dp"

android:title="@string/home" />

android:id="@+id/action_rides"

android:icon="@drawable/ic_local_airport_black_24dp"

android:title="@string/rides"/>

android:id="@+id/action_cafes"

android:icon="@drawable/ic_local_cafe_black_24dp"

android:title="@string/cafes"/>

android:id="@+id/action_hotels"

android:icon="@drawable/ic_local_hotel_black_24dp"

android:title="@string/hotels"/>

I would appreciate any help.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值