andriod studio登录注册页面代码
时间: 2023-09-08 10:15:20 浏览: 26
以下是一个简单的 Android Studio 登录注册页面的代码示例:
**activity_login.xml**
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/login_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/username_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:id="@+id/password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:id="@+id/register_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Don't have an account? Register here." />
</LinearLayout>
```
**activity_register.xml**
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/register_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/username_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:id="@+id/password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="@+id/confirm_password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm Password"
android:inputType="textPassword" />
<Button
android:id="@+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
```
**LoginActivity.java**
```java
public class LoginActivity extends AppCompatActivity {
private EditText usernameEditText, passwordEditText;
private Button loginButton;
private TextView registerTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
usernameEditText = findViewById(R.id.username_edittext);
passwordEditText = findViewById(R.id.password_edittext);
loginButton = findViewById(R.id.login_button);
registerTextView = findViewById(R.id.register_textview);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Handle login button click
String username = usernameEditText.getText().toString();
String password = passwordEditText.getText().toString();
// Do login validation here
}
});
registerTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launch register activity
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
}
});
}
}
```
**RegisterActivity.java**
```java
public class RegisterActivity extends AppCompatActivity {
private EditText usernameEditText, passwordEditText, confirmPasswordEditText;
private Button registerButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
usernameEditText = findViewById(R.id.username_edittext);
passwordEditText = findViewById(R.id.password_edittext);
confirmPasswordEditText = findViewById(R.id.confirm_password_edittext);
registerButton = findViewById(R.id.register_button);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Handle register button click
String username = usernameEditText.getText().toString();
String password = passwordEditText.getText().toString();
String confirmPassword = confirmPasswordEditText.getText().toString();
// Do registration validation here
}
});
}
}
```
注意:这只是一个示例代码,实际应用中需要进行更严格的登录和注册验证。