如何使用最新的 WindowInset API来调整我的对话框和软键盘之间的空间?
我有一个带有一些 EditText 的 BottomSheetDialog。默认动画将在我的 EditText 正下方显示软键盘,它将覆盖我的保存按钮。在做了一些研究之后,我将这一行添加到了我的BottomSheetDialog
片段中
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)
它起作用了(如下图所示)!
但显然SOFT_INPUT_ADJUST_RESIZE
已被弃用。
* @deprecated Call {@link Window#setDecorFitsSystemWindows(boolean)} with {@code false} and
* install an {@link OnApplyWindowInsetsListener} on your root content view that fits insets
* of type {@link Type#ime()}.
Run Code Online (Sandbox Code Playgroud)
而且我不知道如何使用 newOnApplyWindowInsetsListener
来达到相同的效果。这是我当前的BottomSheetDialog
片段:
public class BottomSheetDialog extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// Adding this line works, but it's …
Run Code Online (Sandbox Code Playgroud) android android-layout android-softkeyboard windowinsets android-bottomsheetdialog