search

Home  >  Q&A  >  body text

android - Activity中的Menu怎么才能使用SnackBar(不知道怎么获取view)?

巴扎黑巴扎黑2772 days ago861

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:07:18

    Just use the Layout where the container is located as the view, for example:

    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();
    }
    }

    reply
    0
  • Cancelreply