是否可以向 Snackbar 添加一些按钮或其他不同的视图?

Is it possible to add some buttons or other different View's to Snackbar?

如果可行,您能告诉我该怎么做吗?否则,请告诉我可以使用什么来代替 Snackbar?

你可以这样做。但是,我不建议使用此解决方法。通常你不需要在 snackbar 中放置自定义布局。 Snackbar 是作为所有应用程序通知某事的统一方式而开发的。

 CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);//coordimator layout where you use snackbar
            snackbar = Snackbar.make(coordinatorLayout, "", Snackbar.LENGTH_INDEFINITE);
            Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();//get the snackbar's view
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View snackView = inflater.inflate(R.layout.custom_layout, null);
            snackView.setBackgroundColor(Color.WHITE);
            layout.addView(snackView, 0);//add our custom view to snackbar
            snackbar.show();

example custom snackbar