5

I've been scratching my head all day over this. on one of my activities (and only one) when i call up the virtual keyboard the sliding drawer handle appears above it. i managed to fix this problem on all the other activities in my app by putting android:windowSoftInputMode="adjustPan" in every activity in my Manafest.xml file including the activity in question. also as far as i've been able to determine none of the objects on the activity has focus (if one does i cant figure out how to find it). i've checked for focus by using this.getCurrentFocus() then doing view.clearFocus() on the returned view if there was one. so far it hasn't returned a view so as far as i can tell nothing has focus.

any ideas?

iHorse
  • 113
  • 1
  • 4
  • 1
    I ran into the same issue and found your question as first result. If you did get a working solution feel free to post it below. – Ben Weiss Sep 16 '11 at 08:51

1 Answers1

0

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);
Matt M
  • 814
  • 11
  • 23