Android library to display a BottomSheet in foreground and pass the activity into background.
implementation("com.mbiamont:foreground-bottomsheet:0.1.0")
implementation 'com.mbiamont:foreground-bottomsheet:0.1.0'
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_foreground_bottomsheet"
android:backgroundTint="YOUR_BACKGROUND_COLOR_HERE">
<!-- Your layout here -->
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
import com.mbiamont.foregroundbottomsheet.ForegroundBottomSheet
class ExampleForegroundBottomSheet : ForegroundBottomSheet() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.YOUR_LAYOUT_HERE, container, false)
}
}
ForegroundBottomSheet
is a simple BottomSheetDialogFragment
, so you can show it or dismiss it using the same functions.
Example
class MainActivity : AppCompatActivity() {
fun openForegroundBottomSheet() {
ExampleForegroundBottomSheet().show(supportFragmentManager, "YOUR_TAG")
}
}
class ExampleForegroundBottomSheet : ForegroundBottomSheet() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
closeDialogButton.setOnClickListener {
dismiss()
}
}
}
By default, a ForegroundBottomSheet
can be closed when dragged down.0
It can be disabled by overriding the method onCreateBottomSheetBehavior()
Example:
override fun onCreateBottomSheetBehavior(behavior: BottomSheetBehavior<View>) {
super.onCreateBottomSheetBehavior(behavior)
behavior.isDraggable = false
}
The BottomSheet
won't be able to be closed when dragging down.