问题
I have a problem with soft keyboard overlapping parts of EditTexts.
When I click my EditTexts the soft keyboard appears just below the text, which means that a part of the text box is not shown as the soft keyboard overlaps it.
Any ideas how to increase the distance between EditText and Soft keyboard?
回答1:
There will be certain Solutions available that some times works and some times not what I am using is working and will handle your scenario Use the following Step by step
1- Add Scroll view to your layout inside the main layout
2- get Its reference
3- now use the following code snippet
editTextField.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
v.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
/*if(Build.VERSION.SDK.equals("4.1.1")||Build.VERSION.SDK.equals("4.1.2"))
{
}
else
{*/
scrollView.scrollBy(0, 150);
//}
}
}, 500);
}
});
when ever screen needs to adjust the overlay it will scroll up the screen
回答2:
Just Try this,
Add gravity Bottom in Edit text and provide padding bottom As you need.
<EditText
android:gravity="bottom"
android:paddingBottom="10dp"
................
/>
回答3:
Try this way
In your mainfest.xml
<activity
android:name="YourActivity"
android:windowSoftInputMode="stateHidden|adjustResize" />
回答4:
The problem wasn't caused by EditText, but TextViews that messed up the layout.
来源:https://stackoverflow.com/questions/18658359/how-to-set-the-distance-from-soft-keyboard-to-edittext