android studio登陆注册界面代码
时间: 2023-06-26 14:05:50 浏览: 64
以下是一个简单的 Android Studio 登录注册界面的代码示例:
activity_main.xml:
```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log in"/>
<TextView
android:id="@+id/tv_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Don't have an account? Sign up"/>
</LinearLayout>
```
MainActivity.java:
```
public class MainActivity extends AppCompatActivity {
private EditText etUsername, etPassword;
private Button btnLogin;
private TextView tvSignup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = findViewById(R.id.et_username);
etPassword = findViewById(R.id.et_password);
btnLogin = findViewById(R.id.btn_login);
tvSignup = findViewById(R.id.tv_signup);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
// Check if username and password are correct
// If correct, start new activity
// If incorrect, display error message
}
});
tvSignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Start new activity for sign up
}
});
}
}
```
请注意,这只是一个示例,您需要在实际应用中根据需要进行修改。