android-menudrawer icon indicating copy to clipboard operation
android-menudrawer copied to clipboard

Menu Drawer will grab focus when Not currently Shown

Open kingargyle opened this issue 11 years ago • 4 comments

Currently I'm using Menu Drawer with the serenity-for-android project. One thing I've noticed is that items in the menu drawer will gain focus periodically when using a D-Pad for navigation and the menu drawer is currently not displayed.

In order to work around this, I've had to make sure items in the drawer are not visibile views when the drawer is off screen. However this makes for some messy coding when trying to get the drawer working the same between a Touch screen interface and one where only a D-Pad is available. It would be nice to have the Menu Drawer only respond to Focus events if the Drawer and it's items are visible on the screen, otherwise none of the drawer items should respond to request for focus.

kingargyle avatar Jan 02 '14 17:01 kingargyle

Hi @kingargyle ,

Can you please explain the above via a code sample ? Even i m also facing the same issue and having problems resolving them .

way2jatin avatar Jan 15 '18 13:01 way2jatin

Basicly when you close the drawer you need to make all the views in the drawer invisible. Then when the drawer opens, make the views visible and set the focus to one of the newly visible views.

kingargyle avatar Jan 16 '18 00:01 kingargyle

I tried with the following code sample ...

mMenuDrawer.getMenuDrawer().setOnDrawerStateChangeListener(new OnDrawerStateChangeListener() {
            @Override
            public void onDrawerStateChange(final int oldState, final int newState) {
                if (newState == MenuDrawer.STATE_CLOSED){
                    mMenuDrawer.getMenuView().setVisibility(View.GONE);
                }
                else {
                    mMenuDrawer.getMenuView().setVisibility(View.VISIBLE);
                }
            }
        });

But i m still facing the same issue. Although , if i enable hardwareAccelerated as true for the activity, then it works fine.

way2jatin avatar Jan 16 '18 05:01 way2jatin

I also specifically call requestFocus when opening and closing the drawers to help give the system some info on which item should have focus when opening and closing the drawers.

https://github.com/NineWorlds/serenity-android/blob/develop/serenity-app/src/main/java/us/nineworlds/serenity/MainActivity.java#L151

kingargyle avatar Jan 16 '18 18:01 kingargyle