小编Jos*_*phW的帖子

如何使用最新的 WindowInset API 在出现软键盘时调整对话框布局

题:

如何使用最新的 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

3
推荐指数
3
解决办法
3986
查看次数