I have the following bottom sheet dialog code:
abstract class BaseMvpBottomSheetFragment : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
if (isFullscreen) { // true
dialog.setOnShowListener {
val bottomSheetDialog = it as BottomSheetDialog
bottomSheetDialog
.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
?.let { bottomSheetFl ->
from(bottomSheetFl).apply {
state = STATE_EXPANDED // This code is called, I've checked it with debugger
}
}
}
}
return dialog
}
And the following layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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/containerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorTransparent"
tools:background="#000000">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_bottom_sheet">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/closeIv"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close"
tools:ignore="ContentDescription" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/searchEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:drawableEnd="@drawable/ic_search_clear"
android:imeOptions="actionSearch"
android:inputType="text"
android:lines="1"
android:maxLines="1"
app:layout_constraintTop_toBottomOf="@id/closeIv" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/modelsRv"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/headerLayout"
tools:listitem="@layout/view_item_model" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
I want dialog to be initially expanded (and layout to take all vertical space), but when RecyclerView is empty, it takes no space at all:
I've tried other solutions on SO, but they did not work for me.
from Initially expanded BottomSheetDialog not working

No comments:
Post a Comment