直接用容器所在的Layout作為view就行了,例如:
public class SnackbarTestActivity extends Activity { CoordinatorLayout container; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_snackbar_test); container = (CoordinatorLayout) findViewById(R.id.container); } public void createSnackbar(View v) { Snackbar.make(container, "SnackbarTest", Snackbar.LENGTH_LONG).show(); } }
直接用容器所在的Layout作為view就行了,例如: