android登录注册页面
时间: 2023-10-18 21:09:37 浏览: 26
以下是一个简单的Android登录注册页面的示例代码:
activity_login.xml
```xml
<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">
<EditText
android:id="@+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:id="@+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>
<TextView
android:id="@+id/text_view_register"
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:id="@+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
<EditText
android:id="@+id/edit_text_confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/button_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register"/>
</LinearLayout>
```
LoginActivity.java
```java
public class LoginActivity extends AppCompatActivity {
private EditText mUsernameEditText;
private EditText mPasswordEditText;
private Button mLoginButton;
private TextView mRegisterTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mUsernameEditText = findViewById(R.id.edit_text_username);
mPasswordEditText = findViewById(R.id.edit_text_password);
mLoginButton = findViewById(R.id.button_login);
mRegisterTextView = findViewById(R.id.text_view_register);
mLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO: Implement login logic
}
});
mRegisterTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
}
}
```
RegisterActivity.java
```java
public class RegisterActivity extends AppCompatActivity {
private EditText mUsernameEditText;
private EditText mPasswordEditText;
private EditText mConfirmPasswordEditText;
private Button mRegisterButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mUsernameEditText = findViewById(R.id.edit_text_username);
mPasswordEditText = findViewById(R.id.edit_text_password);
mConfirmPasswordEditText = findViewById(R.id.edit_text_confirm_password);
mRegisterButton = findViewById(R.id.button_register);
mRegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO: Implement registration logic
}
});
}
}
```
这些代码创建了一个简单的登录和注册界面,当用户点击“登录”按钮时,可以在LoginActivity中执行登录逻辑,当用户点击“注册”按钮时,可以在RegisterActivity中执行注册逻辑。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)