Android开发实战——登录注册页面(附源码)
时间: 2023-07-31 16:07:37 浏览: 211
很高兴为您解答关于Android开发的问题。以下是登录注册页面的示例代码:
1. activity_login.xml
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="28sp"
android:textColor="@android:color/black"
android:layout_gravity="center_horizontal"/>
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:hint="Email"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Login"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Don't have an account?"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/tv_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:textColor="@android:color/holo_blue_light"/>
</LinearLayout>
```
2. activity_register.xml
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:textSize="28sp"
android:textColor="@android:color/black"
android:layout_gravity="center_horizontal"/>
<EditText
android:id="@+id/et_fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:hint="Full Name"/>
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Email"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Register"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Already have an account?"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/tv_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="@android:color/holo_blue_light"/>
</LinearLayout>
```
3. LoginActivity.java
```
public class LoginActivity extends AppCompatActivity {
private EditText etEmail, etPassword;
private Button btnLogin;
private TextView tvRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etEmail = findViewById(R.id.et_email);
etPassword = findViewById(R.id.et_password);
btnLogin = findViewById(R.id.btn_login);
tvRegister = findViewById(R.id.tv_register);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Perform login logic
}
});
tvRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
}
});
}
}
```
4. RegisterActivity.java
```
public class RegisterActivity extends AppCompatActivity {
private EditText etFullname, etEmail, etPassword;
private Button btnRegister;
private TextView tvLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
etFullname = findViewById(R.id.et_fullname);
etEmail = findViewById(R.id.et_email);
etPassword = findViewById(R.id.et_password);
btnRegister = findViewById(R.id.btn_register);
tvLogin = findViewById(R.id.tv_login);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Perform registration logic
}
});
tvLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(intent);
}
});
}
}
```
这个示例代码可以作为一个基础框架供您的开发使用。当然,您需要根据您的具体要求对代码进行修改。
阅读全文