NavigationView 打开时如何隐藏 snackbar?

How hide snackbar when NavigationView open?

如何在 shackbar 显示时隐藏 NavigationView

这样 snackbar 就不会重叠 NavigationView

您可以使用Snackbar Callbacks

snackbar.addCallback(new Snackbar.Callback() {

    @Override
    public void onDismissed(Snackbar snackbar, int event) {
      //see Snackbar.Callback docs for event details
      ...  
    }

    @Override
    public void onShown(Snackbar snackbar) {
       drawerLayout.closeDrawer(GravityCompat.START);
    }
  });

试试这个

  • 这里有two条路可以close your drawer

    1. close 抽屉 animation 像这样

snackbar.addCallback(new Snackbar.Callback() {

@Override
public void onDismissed(Snackbar snackbar, int event) {
  //see Snackbar.Callback docs for event details
  ...  
}

@Override
public void onShown(Snackbar snackbar) {
   drawerLayout.closeDrawer(GravityCompat.START);
}
});

  1. close抽屉没有animation像这样

snackbar.addCallback(new Snackbar.Callback() {

@Override
public void onDismissed(Snackbar snackbar, int event) {
  //see Snackbar.Callback docs for event details
  ...  
}

@Override
public void onShown(Snackbar snackbar) {
   drawerLayout.closeDrawer(GravityCompat.START,false);
}
});