Keyboard overlapping EditText on click

戏子无情 提交于 2019-11-28 01:49:13

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:

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

android:windowSoftInputMode="adjustPan" 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!