Reputation: 11
I shifted the whole layout of my page by 250 when user inputs on the two EditText fields, and I need to shit it back when the keyboard is dismissed, I used
public class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
try{
if (actionId == EditorInfo.IME_ACTION_DONE
|| actionId == EditorInfo.IME_NULL
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
LoginActivity.rootView.setY(0);
return true;
}
}catch (Exception e){
}
return false;
}
} And it works fine, but when I click the back button, the keyboard is also dismissed and the layout is not shifted back. Is there a way to disable the back button only when the soft keyboard is up?
Upvotes: 1
Views: 2352
Reputation: 20563
set a variable when soft keyboard is up (how to check visibility of software keyboard in android?) and check it in your overridden onBackPressed()
method. If keyboard is up, do nothing, otherwise call the super method.
private boolean isKeyboardUp;
@Override
public void onBackPressed()
{
if(isKeyboardUp)
//do nothing
else
super.onBackPressed();
}
Upvotes: 1