【问题标题】:how to change the color of vector asset in FloatingActionButton?如何更改 FloatingActionButton 中矢量资源的颜色?
【发布时间】:2021-10-07 06:44:41
【问题描述】:

这是我的 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 中更改颜色,但仍然无法正常工作,我该如何解决?

祝大家有美好的一天!

【问题讨论】:

    标签: android android-button


    【解决方案1】:

    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

    【讨论】:

    • 我做到了。非常感谢,但为什么 android: 现在可以工作了,你能给我解释一下吗?
    • android 通常用于来自 Android SDK 本身的属性。如果您正在使用支持库,则通常会使用 app。见:stackoverflow.com/questions/29732512/…
    • 哦。我明白了。祝你有美好的一天,兄弟!