0

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

Lingviston
  • 5,479
  • 5
  • 35
  • 67

3 Answers3

0

In onResume of home activity you can hide keyboard by:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
vipul mittal
  • 17,343
  • 3
  • 41
  • 44
0

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.

Lingviston
  • 5,479
  • 5
  • 35
  • 67
-1

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);
Community
  • 1
  • 1
Dheeraj Bhaskar
  • 18,633
  • 9
  • 63
  • 66
  • This is an answer for another question which was asked on SO many times. – Lingviston Dec 24 '13 at 09:08
  • You wanted code to dismiss the keyboard on clicking the "home as up" button. If you don't play nice, start down voting without being clear, no one is going to help you around here. – Dheeraj Bhaskar Dec 24 '13 at 09:19
  • Look at the title: I didn't ask how to dismiss the keyboeard in general. You gave me general answer which can be easily found on SO. While you didn't help you also though I'm not able to find this simple answer myself. – Lingviston Dec 24 '13 at 09:26