Question

I'm using DrawerLayout in my app. I've attached ActionBarDrawerToogle to it. When keyborad is visible I still can call drawer menu. I don't want to. I want my app to behave like Youtube app so when keyboard appears there is no drawer toogle in action bar instead it has "home as up" button which dismisses the keyboard. While ActionBarDrawerToogle handles configuration changing events I though it would do it by default but it's not. How can I achieve this behavior?

My app: can call drawer layout while keyboard is visible My app: can call drawer layout while keyboard is visible Play Store: while keyboard is visible tapping home button will dismiss the keyboard Play Store: while keyboard is visible tapping home button will dismiss the keyboard

Was it helpful?

Solution 2

Now I know how to do it. SearchView have to be added as menu item like this:

<item
    android:id="@+id/menu_search"
    android:icon="@drawable/ic_action_search"
    android:title="@string/projects_menu_search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="always|collapseActionView"/>

The key is that it is set as actionView and icon is set too. After tapping on icon actionView become visible and "up" button also appear. Tapping on "up" button collapses actionView.

OTHER TIPS

In onResume of home activity you can hide keyboard by:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Dismiss keyboard like this

If you want to just dismiss it you can use the following lines of code in your button's on click Event

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top