2

我想要一个BottomSheetDialogFragment可以从几个项目中选择一个项目的地方。我希望它永远不会全屏显示。我想要左上角和右上角的圆角。

出于上述目的,我实现了ItemSelectionBottomSheetDialogFragment如下:

class ItemSelectionBottomSheetDialogFragment : BottomSheetDialogFragment() {

    ...

    override fun getTheme(): Int = R.style.ThemeOverlay_Demo_BottomSheetDialog


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) {
        ...
    }
}

fragment_item_selection.xml:

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.ItemSelectionBottomSheetDialogFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/item_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</FrameLayout>

样式.xml:

    <style name="ThemeOverlay.Demo.BottomSheetDialog" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/Widget.Demo.BottomSheet</item>
    </style>

    <style name="Widget.Demo.BottomSheet" parent="Widget.MaterialComponents.BottomSheet">
        <item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.Demo</item>
    </style>

    <style name="ShapeAppearanceOverlay.Demo" parent="">
        <item name="cornerSizeTopLeft">30dp</item>
        <item name="cornerSizeTopRight">3dp</item>
        <item name="cornerFamily">rounded</item>
    </style>

当我展示片段时,它会从下方出现,并带有圆角。但是,当我向上滑动一点时,底部的工作表对话框不会进一步向上,但顶角会从圆形动画到直角方形。

我该如何解决这个问题?

4

0 回答 0