[英]How to remove the shadow created by bottom sheet dialog fragment in android?
[英]Set fixed height for bottom sheet dialog fragment in android
<?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:id="@+id/layout"
style="@style/AppBottomSheetDialogTheme"
android:layout_height="match_parent"
tools:context=".fragments.bottomsheet.FilterBottomSheetFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:paddingHorizontal="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="10dp"
android:text="Payment method"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcPaymentMethod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<View
style="@style/Divider.Horizontal"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingHorizontal="10dp"
android:text="Bed Size"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcBedSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<View
style="@style/Divider.Horizontal"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingHorizontal="10dp"
android:text="View"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<View
style="@style/Divider.Horizontal"
android:layout_marginTop="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingHorizontal="10dp"
android:text="Facilities"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcFacilities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginHorizontal="13dp"
android:layout_marginVertical="10dp">
<TextView
android:id="@+id/txtClearAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:text="Clear All"
android:textColor="@color/black"
android:textSize="18dp" />
<Button
android:id="@+id/btnApply"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/rounded_corner_button"
android:text="Apply"
android:textAllCaps="false"
android:textColor="@color/white"
app:backgroundTint="@color/primary" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这是底部表单对话框片段的文件 xml。 当它显示在其他片段中时,我想为片段设置固定高度。 因为在底部工作表中我有回收站视图所以当我滚动底部工作表时扩展到全屏。 我不想要那个。 我想为它设置固定高度。 而且我想在滚动时按钮“应用”始终显示在底部。
全高:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = context?.let { BottomSheetDialog(it, theme) }
dialog?.setOnShowListener {
val bottomSheetDialog = it as BottomSheetDialog
val parentLayout =
bottomSheetDialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
parentLayout?.let { bottomSheet ->
val behaviour = BottomSheetBehavior.from(bottomSheet)
setupFullHeight(bottomSheet)
behaviour.state = BottomSheetBehavior.STATE_EXPANDED
}
}
return dialog ?: super.onCreateDialog(savedInstanceState)
}
private fun setupFullHeight(bottomSheet: View) {
val layoutParams = bottomSheet.layoutParams
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT
bottomSheet.layoutParams = layoutParams
}
添加 Layout 自定义固定高度
android:layout_height="500dp"
添加布局 peek 高度
app:behavior_peekHeight="100dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.