Fixed
Status Update
Comments
al...@android.com <al...@android.com>
wi...@gmail.com <wi...@gmail.com> #2
fix is merged. i think it will catch 7.0 release if i'm reading the calendar right :).
Sorry it took so long...
[Deleted User] <[Deleted User]> #3
Better late than never! Thank you Yigit!
[Deleted User] <[Deleted User]> #4
any progress on this?
si...@google.com <si...@google.com> #5
Can you please attach a simple android project (or an APK) that reproduces the issue?
si...@google.com <si...@google.com>
mr...@gmail.com <mr...@gmail.com> #6
Here is a simple android project and apk attached to reproduce the issue
da...@gmail.com <da...@gmail.com> #7
Same issue here. Any progress?
si...@google.com <si...@google.com> #8
Thanks for the APK. We were able to reproduce it on M. It seems that it is fixed on N.
do...@gmail.com <do...@gmail.com> #9
Will this be backported to older platforms (e.g. via support library)? I doubt anyone will still use this if it will only work on N.
[Deleted User] <[Deleted User]> #10
Is there a reliable workaround for existing Android versions?
bb...@gmail.com <bb...@gmail.com> #11
any solution ?
[Deleted User] <[Deleted User]> #12
This will help you
onKeyDown() and onBackPressed() doesn't work for this case. You have to use onKeyPreIme.
Initially, you have to create custom edit text that extends EditText. And then you have to implement onKeyPreIme method which controls KeyEvent.KEYCODE_BACK. After this, one back press enough for solve your problem. This solution works for me perfectly.
CustomEditText.java
public class CustomEditText extends EditText {
Context context;
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// User has pressed Back key. So hide the keyboard
InputMethodManager mgr = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(this.getWindowToken(), 0);
// TODO: Hide your view as you do it in your activity
}
return false;
}
In your XML
<com.YOURAPP.CustomEditText
android:id="@+id/CEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
In your Activity
public class MainActivity extends Activity {
private CustomEditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (CustomEditText) findViewById(R.id.CEditText);
}
}
onKeyDown() and onBackPressed() doesn't work for this case. You have to use onKeyPreIme.
Initially, you have to create custom edit text that extends EditText. And then you have to implement onKeyPreIme method which controls KeyEvent.KEYCODE_BACK. After this, one back press enough for solve your problem. This solution works for me perfectly.
CustomEditText.java
public class CustomEditText extends EditText {
Context context;
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// User has pressed Back key. So hide the keyboard
InputMethodManager mgr = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(this.getWindowToken(), 0);
// TODO: Hide your view as you do it in your activity
}
return false;
}
In your XML
<com.YOURAPP.CustomEditText
android:id="@+id/CEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
In your Activity
public class MainActivity extends Activity {
private CustomEditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (CustomEditText) findViewById(R.id.CEditText);
}
}
Description
To reproduce the bug:
1.) add EditText to your activity near the bottom of it (so it would be covered by keyboard if activity is not panned)
2.) set its gravity attribute to 'center' or 'center_horizontal'
3.) in AndroidManifest.xml set activity's attribute android:windowSoftInputMode="adjustPan"
4.) run the app and tap the edit text -> keyboard is opened, activity is panned and editText is visible
5.) tap the back button to hide the keyboard -> activity is normally displayed
6.) tap the edit text again -> keyboard is opened and covers the edit text; activity is not panned
Note that if EditText's gravity is not set to either 'center' or 'center_horizontal', this cannot be reproduced.
We noticed the bug on Android 4.1, 5.0 and 5.1.