思路就是创建两个布局文件,创建两个activity文件,布局文件和activity要一一对应
第一个activity
ample.app5;t.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;import androidx.appcompat.app.AppCompatActivity;public class Login_Activity extends BaseActivity {ImageButton imageButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {Create(savedInstanceState);setContentView(R.layout.login);imageButton=findViewById(R.id.button_login);imageButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent=new Intent();intent.setClass(Login_Activity.this,Register_Activity.class);startActivity(intent);//重要的是在这里,设置按键监听,设置跳转的界面}});}
}
第一个activity对应的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:background="@mipmap/background_login"><ImageButtonandroid:id="@+id/button_login"android:layout_width="114dp"android:layout_height="114dp"android:layout_marginTop="549dp"android:layout_marginLeft="170dp"android:src="@mipmap/login"/><ImageButtonandroid:id="@+id/button_login2"android:layout_width="114dp"android:layout_height="114dp"android:layout_marginTop="549dp"android:layout_marginLeft="170dp"android:src="@mipmap/login"/></LinearLayout>
第二个activity随意吧,里面不放东西也可以的
ample.app5;t.Intent;
t.SharedPreferences;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;
import android.widget.Button;import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;ample.app5.data.Login;
le.gson.Gson;import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Date;import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;public class Register_Activity extends BaseActivity {Button button_Register;@Overrideprotected void onCreate(Bundle savedInstanceState) {Create(savedInstanceState);setContentView(R.layout.login_password);button_Register = findViewById(ister_button);button_Register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {getData();Intent intent=new Intent();intent.setClass(Register_Activity.this,MainActivity.class);startActivity(intent);}});}}
第二个activity对应的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><EditTextandroid:layout_width="match_parent"android:layout_height="46dp"android:hint="请输入账号"android:id="@+id/edittext1"android:textSize="16sp"android:background="@drawable/yuanxing"android:layout_marginTop="48dp"android:layout_marginLeft="35dp"android:layout_marginRight="35dp" /><EditTextandroid:layout_width="match_parent"android:layout_height="46dp"android:hint="请输入密码"android:id="@+id/edittext2"android:textSize="16sp"android:layout_marginTop="10dp"android:background="@drawable/yuanxing"android:layout_marginLeft="35dp"android:layout_marginRight="35dp"/><Buttonandroid:layout_width="match_parent"android:layout_height="46dp"android:text="登陆"android:id="@+id/register_button"android:textSize="16sp"android:layout_marginTop="20dp"android:background="@drawable/test"android:layout_marginLeft="35dp"android:layout_marginRight="35dp"/></LinearLayout>
最后记得在这里声明一下
下面这里是设置启动页的,就是app启动时界面
本文发布于:2024-01-31 04:28:28,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170664651325478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |