BottomSheetDialogFragment中 使用EditText 键盘 遮挡

2,045 阅读1分钟

需要通过给BottomSheetDialogFragment所在的Activity设置BottomSheetDialogFragment的style解决该问题

1. 定义给BottomSheetDialogFragment使用的主题。

<style name="BottomSheetFragmentTheme" parent="Theme.Design.Light.BottomSheetDialog">

<item name="android:windowIsFloating">false</item>

<item name="android:windowSoftInputMode">adjustResize</item>

</style>

2. 定义给Activity使用的主题。注意该属性 <item name="bottomSheetDialogTheme">@style/BottomSheetFragmentTheme</item>

<style name="AuditTheme" parent="...">

<!-- Primary brand color. -->

.....

<!-- Status bar color. -->

<item name="bottomSheetDialogTheme">@style/BottomSheetFragmentTheme</item>

<!-- Customize your theme here. -->

</style>

3. 给调用BottomSheetDialogFragment子类所在的Activity设置theme。

<activity

android:name="..."

android:exported="true"

android:theme="@style/AuditTheme"

android:windowSoftInputMode="adjustPan|stateHidden" />

修改前

image.png

增加属性后

image.png