This is my workaround.. in the Activity that holds the EditText I have a subclass that extends EditText
. In this subclass I override the onMeasure()
method which checks to see if the keyboard is open.
public static class MyEditText extends EditText {
MyActivity context;
public void setContext(MyActivity context) {
this.context = context;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
Activity activity = (Activity)getContext();
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
int diff = (screenHeight - statusBarHeight) - height;
// assume all soft keyboards are at least 128 pixels high
if (diff>128)
context.showHandle(false);
else
context.showHandle(true);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
Then in the activity, if the keyboard is open the drawer handle is set to a 1px x 1px transparent image, if the keyboard is hidden the real handle is shown:
private void showHandle(boolean show) {
ImageView drawer_handle = (ImageView) findViewById(R.drawable.handle);
if (show)
drawer_handle.setImageResource(R.drawable.handle);
else
drawer_handle.setImageResource(R.drawable.handle_blank);
}
Finally, make sure you call setContext()
in onCreate()
of MyActivity
MyEditText met = (MyEditText) findViewById(R.id.edit_text);
met.setContext(this);