D.Blazer D.Blazer - 6 months ago 28
Java Question

Using MikePenz drawer, where can i handle onDrawerOpen, close soft keyboard

i am using mikepenz drawer, i want my softkeyboard to be closed when ik open my drawer, didnt have a problem with doing this with the on hamburger item press, but can find where to handle closing the keyboard on opening the drawer by sliding.

Answer

after the information t0mm13b pointed me to, this is how i did it.

    result = new DrawerBuilder()
            .withActivity(this)
            .withTranslucentStatusBar(false)
            .withActionBarDrawerToggle(false)
            .addDrawerItems(drawerItemsArray)
            .withSavedInstance(savedInstanceState)
            .withOnDrawerListener(new Drawer.OnDrawerListener() {
                @Override
                public void onDrawerOpened(View view) {
                }

                @Override
                public void onDrawerClosed(View view) {
                }

                @Override
                public void onDrawerSlide(View view, float v) {
                    removeSoftKeyboard();
                }
            })
            .build();

remove soft keyboard method

public void removeSoftKeyboard() {
    InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
}
Comments