Skip to content

Instantly share code, notes, and snippets.

fun transform(fab: FloatingActionButton) {
if (fab.isVisible) {
fab.hide(object : FloatingActionButton.OnVisibilityChangedListener() {
override fun onHidden(fab: FloatingActionButton?) {
super.onHidden(fab)
ValueAnimator.ofFloat(materialShapeDrawable.interpolation, 0F).apply {
addUpdateListener { materialShapeDrawable.interpolation = it.animatedValue as Float }
start()
}
}
ValueAnimator.ofFloat(materialShapeDrawable.interpolation, finishState).apply {
addUpdateListener { materialShapeDrawable.interpolation = it.animatedValue as Float }
doOnEnd { fab.show() }
start()
}
<?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"
tools:context=".MainActivity">
<com.vadmax.fabbottomnavigationview.FabBottomNavigationView
android:id="@+id/bottomNavigationView"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="@drawable/ic_android"
android:title="@null" />
<item
android:icon="@drawable/ic_android"
android:title="@null" />
<?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"
tools:context=".MainActivity">
<com.vadmax.fabbottomnavigationview.FabBottomNavigationView
android:id="@+id/bottomNavigationView"
val materialShapeDrawable = MaterialShapeDrawable(shapePathModel).apply {
setTint(ContextCompat.getColor(context, R.color.bottom_bar))
shadowElevation = 4
shadowRadius = 16
isShadowEnabled = true
paintStyle = Paint.Style.FILL_AND_STROKE
}
background = materialShapeDrawable
val shapePathModel = ShapePathModel().apply {
topEdge = topCurvedEdgeTreatment
}
val topCurvedEdgeTreatment =TopCurvedEdgeTreatment(fabCradleMargin, fabCradleRoundedCornerRadius, cradleVerticalOffset).apply {
fabDiameter = fabSize
}
class FabBottomNavigationView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : BottomNavigationView(context, attrs, defStyleAttr) {
init {
//There will be magic
}
}
import com.google.android.material.shape.EdgeTreatment
import com.google.android.material.shape.ShapePath
class TopCurvedEdgeTreatment(
var fabCradleMargin: Float,
var fabCradleRoundedCornerRadius: Float,
var cradleVerticalOffset: Float
) : EdgeTreatment() {
var fabDiameter: Float = 0F