Keyboard overlapping EditText on click

后端 未结 2 1172
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 15:06

In my fragment I have an editText inside a scrollview and when I click on that I set it to open like this:

getActivity().getWindow().setSoftInputMode(WindowM         


        
2条回答
  •  借酒劲吻你
    2020-12-11 15:36

    What about setting RESIZE instead of PAN? You will be able to keep your EditText above the SoftKeyboard. Try as follows:

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    

    However, instead of doing this at runtime, you can set it in the manifest as an Activity (parent) attribute. This will also be handled in your fragment (child):

    
    

    Then, as you can see, the EditText is above the SoftKeyboard, but from your layout, you have a TextView with android:layout_alignParentBottom="true" attribute which will overlap the EditText:

    To prevent this behaviour, just set the ScrollView above the last TextView as follows:

     
    

    And you will get the following result:

提交回复
热议问题