1、场景描述
com.google.android.material.floatingactionbutton.FloatingActionButton 控件在AndroidStudio中预览,图标是什么颜色,就显示什么颜色,但是一运行到手机,则全变成黑色图标了。
- 尝试修改图标颜色,无果;
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M318.74,178.49C238.25,185.48 178.29,256.45 178.29,337.26v2.88c0,80.96 65.3,146.29 145.83,146.29h137.98a24.72,24.72 0,0 0,24.72 -24.72V332.16c0,-89.76 -76.65,-161.61 -168.08,-153.67zM691.44,177.89c-85.19,0 -154.27,69.07 -154.27,154.26v129.55a24.72,24.72 0,0 0,24.72 24.72h129.55C776.64,486.43 845.71,417.35 845.71,332.16c0,-85.19 -69.07,-154.26 -154.27,-154.26zM178.29,691.91c0.04,85.15 69.05,154.16 154.2,154.2 85.97,0.04 154.33,-72.87 154.33,-158.85v-112.09c0,-26.57 -11.04,-37.6 -24.68,-37.6H337.14C251.16,537.57 178.25,605.93 178.29,691.91zM686.33,537.57H561.9a24.72,24.72 0,0 0,-24.72 24.72v129.55c0,85.19 69.07,154.26 154.26,154.26 86.16,0 155.82,-70.64 154.24,-157.15 -1.54,-84.92 -74.4,-151.38 -159.34,-151.38z"
android:fillColor="#ffffff00"/>
</vector>
- 尝试修改tint属性,无果;
android:tint="#ffff0000"
- 尝试修改图标引入方式,无果
android:src="@drawable/ic_more"
app:srcCompat="@drawable/ic_more"
- ……
2、发现原因
各种修改都没有效果,但是预览界面是有效果的,考虑到运行的时候用的别的主题,可能会有影响,然后切换到默认主题,问题解决
3、总结
下面这主题会导致FloatingActionButton图标颜色时黑色,无法改变,慎用。
Theme.MaterialComponents.DayNight.NoActionBar