首页 > 解决方案 > 如何更改 FloatingActionButton 中矢量资源的颜色?

问题描述

这是我的 FloatingActionButton

<com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/white"
                    android:focusable="true"
                    android:src="@drawable/ic_camera_24"
                    android:tint="@color/green"
                    app:fabSize="mini"
                    app:rippleColor="@color/green" />

我尝试更改布局 ic_camera_24.xml 中的颜色,但仍然无法正常工作,我该如何解决?

祝大家拥有美好的一天!

标签: androidandroid-button

解决方案


用app:srcCompatapp:tint试试这个:

<com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/white"
                    android:focusable="true"
                    app:srcCompat="@drawable/ic_camera_24"
                    app:tint="@color/green"
                    app:fabSize="mini"
                    app:rippleColor="@color/green" />

源代码:https ://material.io/components/buttons-floating-action-button/android#mini-fabs


推荐阅读