title: How to adjust dialog layout when soft keyboard appears using the latest WindowInset API
body: <h2>Question:</h2>
  <p>How to use the <strong>latest WindowInset API</strong> to adjust space betweeen my dialog and softkeyboard?</p>
  <hr />
  <p>I have a BottomSheetDialog with some EditText. The default animation will show the soft keyboard right below my EditText which will cover my save button. After doing some research, I added this line into my <code>BottomSheetDialog</code> fragment</p>
  <pre><code>getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
  </code></pre>
  <p>And it worked (as the picture is shown down below)!</p>
  <p><a href="https://i.stack.imgur.com/y9IUu.png" rel="noreferrer">This is what I wanted</a></p>
  <p>But apparently <code>SOFT_INPUT_ADJUST_RESIZE</code> is deprecated.</p>
  <pre><code>   * @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()}.
  </code></pre>
  <p>And I couldn't figure out how to use the new <code>OnApplyWindowInsetsListener</code> to achieve the same effect.
  Here is my current <code>BottomSheetDialog</code> fragment:</p>
  <pre><code>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 deprecated in API 30
  //      getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        
          getDialog().getWindow().setDecorFitsSystemWindows(false);
          view = inflater.inflate(R.layout.fragment_bottom_dialog_cash, container, false);
          view.setOnApplyWindowInsetsListener((v, insets) -&gt; {
              Log.d(&quot;dialog&quot;, &quot;onCreateView: &quot;);
              Insets imeInsets = insets.getInsets(WindowInsets.Type.ime());
              v.setPadding(0,0,0,imeInsets.bottom);
              return insets;
          });
          return view;
      }
  </code></pre>
  <p>I use an onclicklistener in another fragment to show this dialog. Code in <code>Another fragment</code></p>
  <pre><code>    @Override
      public void onItemClick(int position) {
          BottomSheetDialog dialog = new BottomSheetDialog();
          dialog.show(getParentFragmentManager(), &quot;BottomSheetDialog&quot;);
      }
  </code></pre>
  <p>In fact, the log indicates that the listener is never triggered when the soft keyboard pop up.
  FYI, I'm following <a href="https://www.youtube.com/watch?v=acC7SR1EXsI&amp;ab_channel=AndroidDevelopers" rel="noreferrer">this video</a> and <a href="https://blog.stylingandroid.com/android11-windowinsets-part1" rel="noreferrer">this blog</a>.</p>