当前位置:   article > 正文

用Android Studio编写一个登录界面和注册界面并可以跳转_android的登录注册界面代码

android的登录注册界面代码

下面是使用 Android Studio 编写一个简单的登录界面和注册界面,并实现跳转的示例代码

首先,在 res/layout 目录下创建一个名为 activity_login.xml 的布局文件,作为登录界面的布局:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical">
  5. <EditText
  6. android:id="@+id/editTextEmail"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:hint="Email" />
  10. <EditText
  11. android:id="@+id/editTextPassword"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:hint="Password"
  15. android:inputType="textPassword" />
  16. <Button
  17. android:id="@+id/buttonLogin"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:text="Login" />
  21. <TextView
  22. android:id="@+id/textViewRegister"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="Register" />
  26. </LinearLayout>

接下来,在 res/layout 目录下创建一个名为 activity_register.xml 的布局文件,作为注册界面的布局:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical">
  5. <EditText
  6. android:id="@+id/editTextName"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:hint="Name" />
  10. <EditText
  11. android:id="@+id/editTextEmail"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:hint="Email" />
  15. <EditText
  16. android:id="@+id/editTextPassword"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:hint="Password"
  20. android:inputType="textPassword" />
  21. <Button
  22. android:id="@+id/buttonRegister"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="Register" />
  26. </LinearLayout>

然后,在 LoginActivity.java 中编写登录界面的逻辑代码:

  1. import android.content.Intent;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.TextView;
  7. public class LoginActivity extends AppCompatActivity {
  8. private TextView textViewRegister;
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_login);
  13. textViewRegister = findViewById(R.id.textViewRegister);
  14. textViewRegister.setOnClickListener(new View.OnClickListener() {
  15. @Override
  16. public void onClick(View v) {
  17. Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
  18. startActivity(intent);
  19. }
  20. });
  21. }
  22. }

最后,在 RegisterActivity.java 中编写注册界面的逻辑代码:

  1. import android.support.v7.app.AppCompatActivity;
  2. import android.os.Bundle;
  3. public class RegisterActivity extends AppCompatActivity {
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_register);
  8. }
  9. }

以上代码就是一个简单的登录界面和注册界面的实现,并且可以通过点击 "Register" 文本进行跳转。记得在 AndroidManifest.xml 文件中注册 LoginActivity 和 RegisterActivity。这样,您就可以在 Android Studio 中运行应用程序,并测试登录界面和注册界面的跳转功能了。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号