Android on Drawer Closed Listener

前端 未结 3 462
时光说笑
时光说笑 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 04:14

    reVerse answer is right in case you are using ActionBar as well. in case you just use the DrawerLayout directly, you can add a DrawerListener to it:

    View drawerView = findViewById(R.id.drawer_layout);
    if (drawerView != null && drawerView instanceof DrawerLayout) {
        mDrawer = (DrawerLayout)drawerView;
        mDrawer.setDrawerListener(new DrawerListener() {
                @Override
                public void onDrawerSlide(View view, float v) {
    
                }
    
                @Override
                public void onDrawerOpened(View view) {
    
                }
    
                @Override
                public void onDrawerClosed(View view) {
                    // your refresh code can be called from here
                }
    
                @Override
                public void onDrawerStateChanged(int i) {
    
                }
            });
    }
    

    As per kit's comment, addDrawerListener() should be used now that setDrawerListener() has been deprecated.

提交回复
热议问题