Keyboard overlapping EditText on click

后端 未结 2 1169
爱一瞬间的悲伤
爱一瞬间的悲伤 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:35

    Try this, add this code in your AndroidManifest.xml activity

    android:windowSoftInputMode="adjustPan" 
    
    0 讨论(0)
  • 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):

    <activity
        android:name=".NameActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
    

    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:

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/ret"> <!-- instead of "footer" -->
    

    And you will get the following result:

    0 讨论(0)
提交回复
热议问题