Backdrop
This library makes it easy to implement a Backdrop pattern with a CoordinatorLayout
Download
JCenter (Recommended):
For support library:
dependencies {
implementation 'ru.semper-viventem.backdrop:backdrop:0.1.5'
}
For Android X:
dependencies {
implementation 'ru.semper-viventem.backdrop:backdrop:0.1.5_x'
}
JitPack:
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Semper-Viventem:BackdropView:0.1.5'
}
How to use it?
You need to add a layout Toolbar, back container and foreground container
Add BackdropBehavior to the Foreground View Container:
XML
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/backContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- anything -->
</LinearLayout>
<!-- Add BackdropBehavior to this view -->
<android.support.design.card.MaterialCardView
android:id="@+id/foregroundContainer"
app:layout_behavior="ru.semper_viventem.backdrop.BackdropBehavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- anything -->
</android.support.design.card.MaterialCardView>
</android.support.design.widget.CoordinatorLayout>
Kotlin
I used this extension to search for behavior:
fun <T : CoordinatorLayout.Behavior<*>> View.findBehavior(): T = layoutParams.run {
if (this !is CoordinatorLayout.LayoutParams) throw IllegalArgumentException("View's layout params should be CoordinatorLayout.LayoutParams")
(layoutParams as CoordinatorLayout.LayoutParams).behavior as? T
?: throw IllegalArgumentException("Layout's behavior is not current behavior")
}
...
val backdropBehavior: BackdropBehavior = foregroundContainer.findBehavior() // find behavior
with(backdropBehavior) {
attachBackContainer(R.id.backContainer) // set back container
attachToolbar(R.id.toolbar) // set toolbar
// set navigation icons for toolbar
setClosedIcon(R.drawable.ic_menu)
setOpenedIcon(R.drawable.ic_close)
// add listener
addOnDropListener(object : BackdropBehavior.OnDropListener {
override fun onDrop(dropState: BackdropBehavior.DropState, fromUser: Boolean) {
// TODO: handle listener
}
})
}
...