Android adjustpan not working after the first time

前端 未结 8 901
生来不讨喜
生来不讨喜 2020-12-01 05:55

My problem: starting from the second time the software keyboard is shown on the screen, it entirely hides my EditText.

Attribute android:windowSoftInputMode=\"adjus

8条回答
  •  天命终不由人
    2020-12-01 06:41

    The problem you're experiencing is now a known platform bug as described here: https://code.google.com/p/android/issues/detail?id=182191

    The fix is not backported and so will not take effect until Android N. Until Android N is your minimum SDK, the following solution is a workaround.

    You can create a custom class extending EditText and override the method onKeyPreIme(int keyCode, KeyEvent event) like this:

    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event)
    {
       if(keyCode == KeyEvent.KEYCODE_BACK)
         {
             clearFocus();
         }
    return super.onKeyPreIme(keyCode, event);
    }
    

    You should also ensure a higher level layout has the ability to be focused so the EditText's focus may be cleared successfully. The following attributes may work for you:

    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    

    Now when the back key is pressed, the EditText loses the focus. Then when you tap the button again, adjustpan will work as intended. (Posting as an answer since the edit was refused.)

提交回复
热议问题