Bottomsheet 圆角,状态展开

Bottomsheet rounded corner with state expanded

我遇到了一个具体问题。我有一个 bottomSheet,我想在 TopLeft 和 TopRight 角上放置一个半径。除非 bottomSheet.state 是 STATE_EXPANDED,否则它会起作用。所以我找到了这个解决方案

@SuppressLint("RestrictedApi", "VisibleForTests")
override fun onCreateDialog(savedInstanceState: Bundle?): BottomSheetDialog {
    val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
    bottomSheetDialog.behavior.disableShapeAnimations()
    return bottomSheetDialog
}

但问题是: 在我的 bottomSheet 中,我有一个 EditText 和一个按钮。为了让键盘位于按钮下方,我必须在我的 onCreateDialog 方法

中添加这行代码
bottomSheetDialog.behavior.state = STATE_EXPANDED

所以当我添加它时,由于某种原因,角不再是圆的......

在这里你可以找到我当前的代码:

@SuppressLint("RestrictedApi", "VisibleForTests")
override fun onCreateDialog(savedInstanceState: Bundle?): BottomSheetDialog {
    val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
    bottomSheetDialog.behavior.disableShapeAnimations()
    bottomSheetDialog.behavior.state = STATE_EXPANDED
    return bottomSheetDialog
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetStyle)
}

这是我的 Style

<style name="BottomSheetStyle" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>

你知道我该怎么做才能完成这项工作吗? bottomSheetDialog.behavior.disableShapeAnimations()

尝试使用以下代码。

//create round_dialog.xml inside drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners
    android:bottomLeftRadius="24dp"
    android:bottomRightRadius="24dp"
    android:topLeftRadius="24dp"
    android:topRightRadius="24dp" />
</shape>


// update you theme file
    <style name="AddDocBottomSheetDialogTheme" 
parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>

<style name="AppModalStyle" 
parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/rounded_dialog</item>
<item name="android:layout_marginHorizontal">15dp</item>
</style>



// Dialog class
class TestDialogFragment : BottomSheetDialogFragment() {
private lateinit var binding: TestDialogFragmentBinding

override fun getTheme(): Int {
    return R.style.AddDocBottomSheetDialogTheme
}
}