Reputation: 479
In my layout I have 3 EditText with validation condition. When soft keyboard is open error message will display below of EditText. When it goes hide EditText will move down error message still placed top of the layout.
I used custom edittext and my layout is in scroll view still error message is not get down with edit text.
I have 3 edit text and on button if we click on button it will validate and if everything is correct it will open new activity.
else if in edit text data is not entered error message display.It is process.
When keyboard is show error message display.Keyboard get hide edittext will back to it place but error message still top of layout.
Upvotes: 3
Views: 1420
Reputation: 29285
It seems to be a bug which hasn't been fixed yet. However you can work around this problem by subclassing EditText
class (i.e. custom class) and implementing its onKeyPreIme
call back method.
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
// User dismissed the keyboard, so hide and re-show the error message
revalidateEditText();
return false;
}
return super.dispatchKeyEvent(event);
}
public void revalidateEditText(){
// Dismiss your original error dialog
setError(null);
// Validate the content and re-show the error message if needed
validate();
}
Derived from: Android: Error popup on EditText doesn't move down when keyboard goes away
Note that by implementing onKeyPreIme
, you can be notified whenever user dismisses the soft keyboard.
Upvotes: 1
Reputation: 711
Try giving this in your scroll view in xml file
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Upvotes: 2