我已经使用选择器和渐变颜色作为图标按下时的着色,来更改 BottomNavigationView 中的图标着色,但是 Android 把所有的图标都变成了紫色,而不是将图标着色为渐变色。我的问题是是否有可能将 BottomNavigationView 中的图标着色为渐变色?
![enter image description here](https://istack.dev59.com/9oR33.webp)
BottomNavigation 代码:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_bottom_main"
android:layout_width="match_parent"
app:itemIconTint="@color/bottom_menu_background"
android:layout_height="wrap_content"
app:menu="@menu/bottom_navigation_main"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
底部菜单背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/button_gradient_blue" android:state_checked="true" />
<item android:color="@color/baseGray"/>
</selector>
button_gradient_blue:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="@dimen/base_button_radius" />
<gradient android:angle="0" android:startColor="@color/light_blue_gradient_start"
android:endColor="@color/light_blue_gradient_end" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="@dimen/base_button_radius" />
<solid android:color="@color/button_pressed_color"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="@dimen/base_button_radius" />
<gradient android:angle="0" android:startColor="@color/light_blue_gradient_start"
android:endColor="@color/light_blue_gradient_end" />
</shape>
</item>
</selector>