Android on Drawer Closed Listener

前端 未结 3 464
时光说笑
时光说笑 2020-12-15 03:36

I have an application using navigation drawer that provides list of locations. In the drawer, there are several options (like choosing country, city, etc) that user can setu

3条回答
  •  一向
    一向 (楼主)
    2020-12-15 03:52

    When you setup the ActionBarDrawerToggle you can "implement" the onDrawerClosed and onDrawerOpened callbacks. See the following example from the Docs:

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
    
            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                // Do whatever you want here
            }
    
            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                // Do whatever you want here
            }
        };
    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    

    Edit: Now the setDrawerListener is deprecated, use addDrawerListener instead.

提交回复
热议问题