我正在实现一个 UI,其中底部工作表将出现在键盘上方,并带有一个 EditText,供用户输入值。问题是视图与键盘部分重叠,覆盖了底部工作表的底部。
这是底页,没有键盘。
这是显示键盘的底页。
确保显示整个底页的最佳方法是什么?
Thanks.
只是从这个问题重新发布@jblejder键盘隐藏 BottomSheetDialogFragment https://stackoverflow.com/questions/44625365/keyboard-hides-bottomsheetdialogfragment/50948146#50948146因为它对我有用,让其他人更容易找到:
我发现改变这一点的最方便的方法是创建样式:
<style name="DialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
并在 BottomSheetDialogFragment 的 onCreate 方法中进行设置:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)
}
这是它在我的设备上的样子:
====更新====
正如评论中多次提到的,您可能还需要将 BottomSheetDialog 的状态设置为 STATE_EXPANDED,如下面 Nordknight 的回答所示
dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
},0);
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)