使用键盘上方的 EditText 显示整个底部工作表 [英] Show entire bottom sheet with EditText above Keyboard
问题描述
我正在实现一个 UI,其中底部工作表将出现在键盘上方,并带有一个 EditText 供用户输入值.问题是 View 被键盘部分重叠,覆盖了底部工作表的底部.
这是底页,没有键盘.
这是显示键盘的底部表格.
确保显示整个底部工作表的最佳方法是什么?
谢谢.
刚刚从这个问题转发@jblejder
==== 更新 ====
正如在评论中多次提到的,您可能还需要将 BottomSheetDialog 的状态设置为 STATE_EXPANDED,就像下面 Nordknight 的回答一样
dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);dialog.setOnShowListener(new DialogInterface.OnShowListener() {@覆盖public void onShow(DialogInterface dialog) {new Handler().postDelayed(new Runnable() {@覆盖公共无效运行(){BottomSheetDialog d = (BottomSheetDialog) 对话框;FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);}},0);}});
I'm implementing a UI where a bottom sheet will appear above the keyboard with an EditText for the user to enter a value. The problem is the View is being partially overlapped by the keyboard, covering up the bottom of the bottom sheet.
Here is the Bottom Sheet and no keyboard.
Here is the Bottom Sheet with the keyboard showing.
What's the best method to ensure the entire Bottom Sheet is shown?
Thanks.
Just reposting @jblejder from this question Keyboard hides BottomSheetDialogFragment since it worked for me, to make it easier for others to find:
The most convenient way that I found to change this is by creating style:
<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>
And set this in onCreate method of your BottomSheetDialogFragment:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)
}
This is how it looks on my device:
==== UPDATE ====
As already mentioned in the Comments a few times, you might also need to set the state of the BottomSheetDialog to STATE_EXPANDED like in Nordknight's answer below
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);
}
});
这篇关于使用键盘上方的 EditText 显示整个底部工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!