Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Own effort ... It's not the best solution I've developed but anyway ... it works ...</p> <p><strong>Part 1 :</strong> Resize the PopupWindow when the SoftKeyboard appears</p> <ul> <li><p>Use the OnGlobalLayoutListener on the content view</p> <pre><code>contentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { int baseHeight = 0; @Override public void onGlobalLayout() { if(resized) { return; } if(baseHeight &lt;= 0) { baseHeight = contentView.getHeight(); return; } final int diff = baseHeight - contentView.getHeight(); if(diff &gt; 0) { // keyboard is visible window.update( - 1, baseHeight - diff - yPos); resized = true; } } }); </code></pre></li> </ul> <p>When you've done with this, the PopupWindow stays resized even if the SoftKeyboard is hidden. The GlobalLayout event is not fired because the PopupWindow is smaller.</p> <p><strong>Part 2 :</strong> Use a fake PopupWindow to know if the SoftKeyboard is hidden (dirty :()</p> <ul> <li>Build the fake PopupWindow with the real PopupWindow height</li> <li>Don't forget to dismiss the fake when the real one is dismissed</li> <li><p>Show the fake before the real one</p> <pre><code>buildFakePopupWindow(rootHeight); window.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { if(fakeWindow != null) { fakeWindow.dismiss(); } } }); fakeWindow.showAtLocation(parent, Gravity.NO_GRAVITY, xPos, yPos); </code></pre></li> <li><p>Register a GlobalLayoutListener on the fake</p> <pre><code> final View fakeContentView = fakeWindow.getContentView(); fakeContentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { int baseHeight = 0; @Override public void onGlobalLayout() { if(baseHeight &lt;= 0) { baseHeight = fakeContentView.getHeight(); return; } final int diff = baseHeight - fakeContentView.getHeight(); if(diff &lt;= 0 &amp;&amp; resized) { window.update( - 1, WindowManager.LayoutParams.WRAP_CONTENT); resized = false; } } }); </code></pre></li> </ul> <p><strong>I'm pretty sure that is a dirty solution but I didn't find another way to do it.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload