BottomSheetDialog 或 DialogFragment 中edit被键盘部分遮挡

BottomSheetDialog

style.xml中继承Theme.Design.Light.BottomSheetDialog

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

BottomSheetDialog

BottomDialogFragment的onCreate中加入

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetEdit);
} 

注意事项

dialog中内容过高时,需要在show方法后添加如下代码

FrameLayout bottomSheet = findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior<FrameLayout> behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setState(STATE_EXPANDED);
发布了5 篇原创文章 · 获赞 1 · 访问量 84

猜你喜欢

转载自blog.csdn.net/zhuiyuepursuemoon8/article/details/103537538