Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my FloatingActionButton icon black? [duplicate]

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

<?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> 

enter image description here

like image 735
Álysson Alexandre Avatar asked Nov 24 '18 13:11

Álysson Alexandre


People also ask

How do you use a floating action button?

Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

How do I change the size of my floating action button?

To change the size of the Floating action button: To change the size of the floating action button, wrap it with SizedBox() widget and pass custom height and width. SizedBox( height:100, width:100, child:FloatingActionButton( child: Icon(Icons.


2 Answers

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" /> 
like image 166
David Jarvis Avatar answered Sep 29 '22 10:09

David Jarvis


I have an icon(vector) with multiple colors(attached file) but I cannot use app:tint="@color/white" because my icon's color turns to single color such as white and I did not need this.

So I Fixed my problem with set setting app:tint to null:

  app:tint="@null" 

My Icon (SVG) :

enter image description here

like image 32
Abolfazl Kalemati Avatar answered Sep 29 '22 09:09

Abolfazl Kalemati