您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页Android Studio--按钮跳转新页

Android Studio--按钮跳转新页

来源:保捱科技网
MainActivity.xml:
<Button
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Go"
android:onClick="skip"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="28dp" />
MainActivity.java:
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;

onCreate 外声明一个变量:
//声明一个button按钮(不需要和实际按钮同名)
Button bt1;

onCreate 里
//创建 绑定Button资源
bt1 = (Button) findViewById(R.id.btnGo);
//设置Button监听
bt1.setOnClickListener(new MyButtonListener());

onCreate 同级监听:
//实现(需要导入android.view.View和android.content.Intent)
// 实现OnClickListener接口
private class MyButtonListener implements View.OnClickListener {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, other.class);//从MainActivity页面跳转至LoginActivity页面
startActivity(intent);
MainActivity.this.finish();
}
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务