Raunak Pandey
Raunak Pandey

Reputation: 370

FloatingActionButton with RecyclerView

My FloatingActionButton is greyed out. I've tried using the Coordinator layout but it isn't working. Below are the screenshot of the problem and a code snapshot.

Screenshot

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    style="@style/AppTheme">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/alarms_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:scrollbars="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="83dp"
        android:layout_height="61dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:src="@drawable/ic_add_alarm_black_24dp"
        app:backgroundTint="#FFFFFF"
        app:fabSize="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"></com.google.android.material.floatingactionbutton.FloatingActionButton>
</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

Views: 692

Answers (2)

davidm
davidm

Reputation: 1750

First if you use AndroidX be sure to include the following dependency to your app gradle.

implementation 'com.google.android.material:material:1.0.0'

Next replace your FAB in the XML with the code below. The FAB should appear in the bottom-right corner of the screen.

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginBottom="32dp"
        android:src="@drawable/ic_add_alarm_black_24dp"
        android:background="@color/colorAccent"
        app:backgroundTint="@color/colorAccent"
        app:fabSize="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

Upvotes: 1

Hern&#226;ni Pereira
Hern&#226;ni Pereira

Reputation: 324

try this n the xml:

app:backgroundTint="@color/red"

Upvotes: 0

Related Questions