Android studio 三个界面之间跳转程序代码

Android studio 三个界面之间跳转程序代码

功能介绍:
点击第一个按钮 OK 跳转到第二个界面,点击图标第二个界面跳转到第三个界面

界面一:
Android studio 三个界面之间跳转程序代码_第1张图片

界面二:
Android studio 三个界面之间跳转程序代码_第2张图片

界面三:
Android studio 三个界面之间跳转程序代码_第3张图片

第一个界面的代码

activity_main.xml

             //字体大小

MainActivity.java

private Button mBtnJumpToSecondActivity;  //设置私有Button变量mBtnJumpToSecondActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();
}

private void initView() {
    mBtnJumpToSecondActivity = (Button) findViewById(R.id.btn_jumpToSecondActivity);  //先找到这个变量
    mBtnJumpToSecondActivity.setOnClickListener(this);   //再设置点击事件
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_jumpToSecondActivity:  
            jumpToSecondActivity();   //跳转到第二个Activity
            break;  
    }
}

private void jumpToSecondActivity() {
    Intent mIntent = new Intent("cn.edu.sziit.chapter2_firstactivity.ACTION_START");
    startActivity(mIntent);
}

第二个界面代码

activity_second.xml

      //文字大小25sp

SecondActivity.java

private Button mJumpToFirstActivity;                  //设置私有变量mJumpToFirstActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    initView();
}

private void initView() {
    mJumpToFirstActivity = (Button) findViewById(R.id.jumpToThirdActivity);   //找到这个变量
    mJumpToFirstActivity.setOnClickListener(this);      //设置点击事件
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.jumpToThirdActivity:
            jumpToThirdActivity();        //跳转至第三个界面
            break;
    }
}
private void jumpToThirdActivity() {
    Intent mIntent = new Intent(this, ThirdActivity.class);
    startActivity(mIntent);
}

第三个界面代码

activity_third.xml

                      //文字大小

ThirdActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third);
}

你可能感兴趣的:(android)