0

I created a red circle with xml, red_circle.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid
                android:color="@color/Red"/>
        </shape>
    </item>
</layer-list>

I use the above red circle as the background image of my FloatingActionButton :

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:src="@drawable/red_circle"
        app:borderWidth="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

The result is this:

enter image description here

How can I have the red circle cover the whole FloatingActionButton?

Leem
  • 17,220
  • 36
  • 109
  • 159
  • Try this : [https://stackoverflow.com/questions/30969455/android-changing-floating-action-button-color](https://stackoverflow.com/questions/30969455/android-changing-floating-action-button-color) – Maksym V. Feb 14 '18 at 22:17

2 Answers2

0

Change you accent color to Red because your FloatingActionButton theme will be AppTheme.

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
 </style>

Or you also change the color by programmatically

fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(MainActivity.this,R.color.colorRed)));
MashukKhan
  • 1,946
  • 1
  • 27
  • 46
0

No need to create a drawable or color list in java. In your layout xml file, setbackground of FAB by
app:backgroundTint="@color/yourColourRed" Reply me back if it really helps you.

Anuj Kumar
  • 1,092
  • 1
  • 12
  • 26