1

I've build a Navigation drawer thanks to Google documentation and sample from google.

Now I'm searching for a solution to hide keyboard when right slide is closed, because in this slide I've a EditText and when I close the menu, the keyboard still opened.

Last, when I open the menu, the layout comes over the main content. So I wonder if there's an easy way to make that main content followed the menu's movement, Facebook like?

Maxime
  • 1,172
  • 1
  • 13
  • 40

1 Answers1

8

I've find the answer for detection of "On DrawerLayout close".

I just needed to craeate a class which implements implements android.support.v4.widget.DrawerLayout.DrawerListener and override the method onDrawerClosed(View view). Last, I set DrawerListener to my drawer and it works.

For people who prefer practice, this is my code :

public class MyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) 
        DrawerLayout drawer = (DrawerLayout)findViewById(R.id.fullContent);
        drawer.setDrawerListener(new RightMenuListener());
    }


    private class RightMenuListener implements android.support.v4.widget.DrawerLayout.DrawerListener {
        @Override
        public void onDrawerClosed(View view) {
            EditText searchBar = (EditText)findViewById(R.id.searchText);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(searchBar.getWindowToken(), 0);
        }
        [...]
    }
}
Maxime
  • 1,172
  • 1
  • 13
  • 40