为什么我的 FloatingActionButton 图标是黑色的? [英] Why is my FloatingActionButton icon black?

查看:36
本文介绍了为什么我的 FloatingActionButton 图标是黑色的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在使用的代码.我正在使用 androidx.每个 FAB 都有一个黑色图标,即使它是白色的.

Following is the code I'm using. I'm using androidx. Every FAB has a black icon, even if it has a white color.

mylayout.xml

mylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/content_geral" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="24dp"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@drawable/ic_cloud_upload"
        tools:ignore="VectorDrawableCompat" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

style.xml

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

推荐答案

如果您使用的是 AndroidX,要更改图标的颜色,您必须使用 app:tint 反对 android:tint

If you're using AndroidX, to change the color of the icon you must use app:tint opposed to android:tint

<com.google.android.material.floatingactionbutton.FloatingActionButton
    style="@style/Widget.MaterialComponents.FloatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"
    app:backgroundTint="@color/colorPrimary"
    app:tint="@color/white"
    app:srcCompat="@drawable/ic_add"
/>

这篇关于为什么我的 FloatingActionButton 图标是黑色的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆