BottomSheetDialogFragment弹出后遮挡键盘

592 阅读1分钟

onCreateDialog方法中,设置style:

class AddTaskDialog : BottomSheetDialogFragment() {
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        // 解决弹起后键盘遮挡
        setStyle(STYLE_NORMAL, R.style.BottomSheetDialogFragment)
        return super.onCreateDialog(savedInstanceState)
    }
}

style如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="BottomSheetDialogFragment" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowSoftInputMode">adjustResize</item>
        <item name="android:background">@color/transparent</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="bottomSheetStyle">@style/BottomSheetDialogWrapper</item>
    </style>
    <style name="BottomSheetDialogWrapper" parent="Widget.MaterialComponents.BottomSheet.Modal">
        <item name="android:background">@color/transparent</item>
    </style>
</resources>