是否有 SoftInputMode 解决方法来显示整个对话框
Is there a SoftInputMode workaround to show whole dialog
我有一个带有两个 EditText
字段的 DialogFragment
和另一个带有 ImageView
的字段以增加其在这些下方的值,它们都位于 ScrollView
中。
问题是 软键盘的调整模式 一次显示我的整个 DialogFragment
,尽管有 space。
adjustResize
导致 ScrollView
调整大小并隐藏底行。 adjustpan
保持 ScrollView
大小不变,但 软键盘 与底行重叠。
删除 ScrollView
意味着任一选项都会导致键盘重叠。
我希望 DialogFragment 在不调整大小的情况下向上移动屏幕。我能做到吗?理想情况下,我想在 Layout
中保留 ScrollView
以更好地支持非常小的屏幕。
我找到的唯一解决方案是更改对话框片段本身的 window 选项。显然在较小的屏幕上这仍然是一个问题,所以我仍在寻找更好的答案。
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
//I was using android.R.style.Theme_Translucent_NoTitleBar for another issue
//but I don't think the theme makes any difference to how the window is laid out
//that is relevant to the below code
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);
... //Do your usual stuff here
dialog.getWindow().setContentView(...);
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.TOP; //this is the important part
dialog.setCanceledOnTouchOutside(false);
return dialog;
}
我有一个带有两个 EditText
字段的 DialogFragment
和另一个带有 ImageView
的字段以增加其在这些下方的值,它们都位于 ScrollView
中。
问题是 软键盘的调整模式 一次显示我的整个 DialogFragment
,尽管有 space。
adjustResize
导致 ScrollView
调整大小并隐藏底行。 adjustpan
保持 ScrollView
大小不变,但 软键盘 与底行重叠。
删除 ScrollView
意味着任一选项都会导致键盘重叠。
我希望 DialogFragment 在不调整大小的情况下向上移动屏幕。我能做到吗?理想情况下,我想在 Layout
中保留 ScrollView
以更好地支持非常小的屏幕。
我找到的唯一解决方案是更改对话框片段本身的 window 选项。显然在较小的屏幕上这仍然是一个问题,所以我仍在寻找更好的答案。
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
//I was using android.R.style.Theme_Translucent_NoTitleBar for another issue
//but I don't think the theme makes any difference to how the window is laid out
//that is relevant to the below code
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);
... //Do your usual stuff here
dialog.getWindow().setContentView(...);
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.TOP; //this is the important part
dialog.setCanceledOnTouchOutside(false);
return dialog;
}