如何解决无法在Android Studio上的FloatingActionButton的布局文件中更改图标颜色
因此,我有一个具有以下框架的布局文件:
<layout>
<CoordinatorLayout>
<AppBarLayout>
... some tags and stuff ...
</AppBarLayout>
<NestedScrollView>
.... nested scroll view stuff
</NestedScrollView>
<!-- Finally! Here comes.... -->
<FloatingActionButton>
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="8dp"
android:backgroundTint="@color/someDarkBlueColor"
android:tint="@color/colorWhite"
android:src="@drawable/ic_white_camera" />
... closing tags and stuff ....
ic_white_camera如下:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="200dp" android:height="200dp" android:viewportWidth="24.0" android:viewportHeight="24.0">
<path android:fillColor="@color/colorWhite" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,-6.4 0"/>
<path android:fillColor="@color/colorWhite" android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>
@ color / colorWhite 是..您猜到了。白色...
但是android坚持以黑色渲染摄像头图标!
我尝试添加android:tint="@color/colorWhite"
。不行。
添加了android:foregroundTint="@color/colorWhite"
和... Nada!
仍然得到这个:
关于这个的任何线索吗?
最诚挚的问候..:-)
解决方法
如果使用FloatingActionButton
软件包中的com.google.android.material
,则应添加app:tint
而不是android:tint
。然后,在您的xml中,您应该使用app:tint="@color/colorWhite"
而不是android:tint="@color/colorWhite"
。
右边的attributes是:
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: org.springframework.dao.support.PersistenceExceptionTranslationInterceptor
at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:68)
at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:35)
at org.springframework.core.convert.support.GenericConversionService$ConverterAdapter.convert(GenericConversionService.java:385)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
... 139 more
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:srcCompat="@drawable/ic_white_camera"
app:tint="@color/colorWhite"
app:backgroundTint="@color/someDarkBlueColor"/>
与VectorDrawable
一起使用很重要。
我不确定您到底想要什么效果,但是您可以尝试注释或删除此行:
android:backgroundTint="@color/someDarkBlueColor"
或调整someDarkBlueColor
的值。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。