期望:通过点击按钮,实现跳转到另外一个页面
实现:
Button ViewBt = findViewById(R.id.ViewBt);
ViewBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, ViewActivity.class));
}
});
解释:
findViewById :通过id获取控件类
ViewBt.setOnClickListener :添加点击事件
startActivity(new Intent(MainActivity.this, ViewActivity.class)); 启动一个新的activity
****************************跳转还可以传递参数****************************
使用Bundle传递
Intent intent = new Intent(MainActivity.this,FaceActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("glassMode",true);
intent.putExtras(bundle);
startActivity(intent);
接收端处理方式如下:
Bundle bundle = getIntent().getExtras();
if (null != bundle){
glassMode = bundle.getBoolean("glassMode");
Tool_Log.i("glassMode :"+glassMode);
}