• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Transparent background FAB not allowing interaction/blocking interaction

stealthrt

Lurker
Hey all I am trying to figure out why I am unable to interact with the background even though my app has a transparent background? The code below was modified from the official Google Android demos here.

Here is the code I am using:
Java:
class FabTransformationActivity : AppCompatActivity()  {

    private val viewModel: FabTransformationViewModel by viewModels()
private lateinit var fab: FloatingActionButton
private var mWindowManager:/*@@psggbk@@*/WindowManager? = null

private class ItemHolder(val parent: LinearLayout, listener: View.OnClickListener) {
val image: ImageView = parent.findViewById(R.id.image)
val name: TextView = parent.findViewById(R.id.name)

        init {
parent.setOnClickListener(listener)
        }
    }

private val menuOnClick = View.OnClickListener { v ->
val name = v.getTag(R.id.tag_name) as String

        fab.isExpanded = false
    }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var params: WindowManager.LayoutParams
 
setContentView(R.layout.fab_transformation_activity)

val root: CoordinatorLayout = findViewById(R.id.root)
val sheet: CircularRevealCardView = findViewById(R.id.sheet)
val menuHolders: List<ItemHolder> = listOf(
ItemHolder(findViewById(R.id.menu_1), menuOnClick),
ItemHolder(findViewById(R.id.menu_2), menuOnClick),
ItemHolder(findViewById(R.id.menu_3), menuOnClick),
ItemHolder(findViewById(R.id.menu_4), menuOnClick)
        )

fab = findViewById(R.id.fab)

WindowCompat.setDecorFitsSystemWindows(window, false)

        val fabMargin = 16

ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())

fab.updateLayoutParams<CoordinatorLayout.LayoutParams> {
                leftMargin = fabMargin + systemBars.left
                rightMargin = fabMargin + systemBars.right
                bottomMargin = fabMargin + systemBars.bottom
            }

sheet.updateLayoutParams<CoordinatorLayout.LayoutParams> {
                leftMargin = fabMargin + systemBars.left
                rightMargin = fabMargin + systemBars.right
                bottomMargin = fabMargin + systemBars.bottom
            }

            insets
        }
    
viewModel.items.observe(this) { items ->
            menuHolders.forEachIndexed { i, holder ->
if (items.size > i) {
                    val _item = items[i]

                    holder.parent.isVisible = true
holder.parent.setTag(R.id.tag_name, _item.name)
                    holder.name.text = _item.name

Glide.with(holder.image)
.load(_item.image)
.transform(CircleCrop())
.into(holder.image)
                } else {
                    holder.parent.isVisible = false
                }
            }
        }

        fab.setOnClickListener {
            fab.isExpanded = true
        }
    }

    override fun onBackPressed() {
if (fab.isExpanded) {
            fab.isExpanded = false
        } else {
            super.onBackPressed()
        }
    }
}

The layout:
XML:
<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:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <!-- A FAB that expands into a sheet. -->
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        app:elevation="8dp"
        android:contentDescription=""
        app:srcCompat="@drawable/ic_add" />

    <!--
        A sheet that the FAB expands into.
        Use CircularRevealCardView to apply circular reveal effect.
    -->
    <com.google.android.material.circularreveal.cardview.CircularRevealCardView
        android:id="@+id/sheet"
        android:layout_width="256dp"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        android:background="?attr/colorSurface"
        android:visibility="invisible"
        app:elevation="8dp"
        app:layout_behavior="@string/fab_transformation_sheet_behavior"
        tools:visibility="visible">

        <LinearLayout
            android:id="@+id/sheet_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <include
                android:id="@+id/menu_1"
                layout="@layout/menuitems" />

            <include
                android:id="@+id/menu_2"
                layout="@layout/menuitems" />

            <include
                android:id="@+id/menu_3"
                layout="@layout/menuitems" />

            <include
                android:id="@+id/menu_4"
                layout="@layout/menuitems" />

        </LinearLayout>

    </com.google.android.material.circularreveal.cardview.CircularRevealCardView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I can interact with the FAB but when I try moving the background (which is just the standard Android home screen, I never moves.

App not running (can movie the home screen around): enter image description here

Now with the transparent fab: enter image description here

What can I change (or add) in order to get this to work? The goal is to have this FAB button floating regardless of what app is opened.
 
Back
Top Bottom