当前位置: 首页 > wzjs >正文

贵阳建筑公司网站建设wordpress 多标签筛选

贵阳建筑公司网站建设,wordpress 多标签筛选,留言板网页设计代码,网站打开慢怎么回事以下是一个使用Java开发的安卓App,实现账号注册和登录功能的示例代码: 1. 创建一个新的Android项目 在Android Studio中创建一个新的项目,选择"Empty Activity"模板。 2. 设计注册和登录页面的布局 在res/layout目录下创建两个…

以下是一个使用Java开发的安卓App,实现账号注册和登录功能的示例代码:

1. 创建一个新的Android项目

在Android Studio中创建一个新的项目,选择"Empty Activity"模板。

2. 设计注册和登录页面的布局

res/layout目录下创建两个XML布局文件:activity_register.xmlactivity_login.xml

activity_register.xml

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"><EditTextandroid:id="@+id/etUsernameRegister"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="用户名"android:inputType="text" /><EditTextandroid:id="@+id/etPasswordRegister"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="密码"android:inputType="textPassword" /><EditTextandroid:id="@+id/etConfirmPassword"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="确认密码"android:inputType="textPassword" /><Buttonandroid:id="@+id/btnRegister"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="注册" /><TextViewandroid:id="@+id/tvGoToLogin"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="已有账号?去登录"android:textSize="16sp" /></LinearLayout>
activity_login.xml

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"><EditTextandroid:id="@+id/etUsernameLogin"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="用户名"android:inputType="text" /><EditTextandroid:id="@+id/etPasswordLogin"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="密码"android:inputType="textPassword" /><Buttonandroid:id="@+id/btnLogin"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="登录" /><TextViewandroid:id="@+id/tvGoToRegister"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="没有账号?去注册"android:textSize="16sp" /></LinearLayout>

3. 创建注册和登录的Activity

java目录下创建两个Java类:RegisterActivity.javaLoginActivity.java

RegisterActivity.java

java复制

package com.example.userauthapp;import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class RegisterActivity extends AppCompatActivity {private EditText etUsername, etPassword, etConfirmPassword;private Button btnRegister;private TextView tvGoToLogin;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_register);etUsername = findViewById(R.id.etUsernameRegister);etPassword = findViewById(R.id.etPasswordRegister);etConfirmPassword = findViewById(R.id.etConfirmPassword);btnRegister = findViewById(R.id.btnRegister);tvGoToLogin = findViewById(R.id.tvGoToLogin);btnRegister.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String username = etUsername.getText().toString().trim();String password = etPassword.getText().toString().trim();String confirmPassword = etConfirmPassword.getText().toString().trim();if (username.isEmpty() || password.isEmpty() || confirmPassword.isEmpty()) {Toast.makeText(RegisterActivity.this, "请填写所有字段", Toast.LENGTH_SHORT).show();return;}if (!password.equals(confirmPassword)) {Toast.makeText(RegisterActivity.this, "两次输入的密码不一致", Toast.LENGTH_SHORT).show();return;}// 这里可以添加将用户信息保存到数据库的逻辑Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();// 跳转到登录页面Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);startActivity(intent);}});tvGoToLogin.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);startActivity(intent);}});}
}
LoginActivity.java

java复制

package com.example.userauthapp;import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class LoginActivity extends AppCompatActivity {private EditText etUsername, etPassword;private Button btnLogin;private TextView tvGoToRegister;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_login);etUsername = findViewById(R.id.etUsernameLogin);etPassword = findViewById(R.id.etPasswordLogin);btnLogin = findViewById(R.id.btnLogin);tvGoToRegister = findViewById(R.id.tvGoToRegister);btnLogin.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String username = etUsername.getText().toString().trim();String password = etPassword.getText().toString().trim();if (username.isEmpty() || password.isEmpty()) {Toast.makeText(LoginActivity.this, "请填写用户名和密码", Toast.LENGTH_SHORT).show();return;}// 这里可以添加从数据库验证用户信息的逻辑// 假设有一个简单的验证逻辑if (username.equals("test") && password.equals("123456")) {Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();// 跳转到主页面Intent intent = new Intent(LoginActivity.this, MainActivity.class);startActivity(intent);} else {Toast.makeText(LoginActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();}}});tvGoToRegister.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);startActivity(intent);}});}
}

4. 创建主页面

res/layout目录下创建activity_main.xml布局文件,作为用户登录成功后的主页面。

activity_main.xml

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:gravity="center"android:padding="16dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="欢迎来到主页面"android:textSize="24sp" /></LinearLayout>
MainActivity.java

java复制

package com.example.userauthapp;import android.os.Bundle;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}
}

5. 配置AndroidManifest.xml

AndroidManifest.xml中添加Activity的声明。

xml复制

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.userauthapp"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.UserAuthApp"><activity android:name=".MainActivity" /><activity android:name=".LoginActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".RegisterActivity" /></application></manifest>

6. 运行应用

在Android Studio中运行应用,你可以看到登录和注册页面,用户可以进行注册和登录操作。

注意:上述代码中的用户验证逻辑是简单的硬编码示例,在实际应用中,你需要连接到后端服务器或数据库来处理用户数据,并确保数据的安全性和完整性。

http://www.dtcms.com/wzjs/612805.html

相关文章:

  • 百度移动网站排名中国深圳航空公司官方网站
  • 网站建设站建设好吗全球华设计大奖
  • 阿里云简单网站建设中国企业500强公司排名
  • 网站怎么换服务器宿豫建设局网站
  • 网站开发 公司 深圳网页代理网站
  • 精品网站建设费用 c磐石网络福田庆三价格
  • 石河子网站建设wordpress设置中英版
  • 企业网站必须做可信认证吗淘宝seo是什么意思
  • 网站建设属于会计哪个科目网站的创新点
  • 传奇怎么做网站阿里云外贸建站
  • 建设行政主管部门官方网站wordpress英文版改成中文字体
  • 企业网站的功能网站域名能迁移吗
  • 网站开发过程可分为网站建设包括哪些知识
  • 景安网站备案查询flash网站建设
  • 网站开发申请报告某企业网站网页设计模板
  • django网站开发视频教程下载做贸易的都有什么网站
  • 代发货网站建设云开发技术
  • 怎么利用源码做网站网站空间数据丢失
  • 邯郸做外卖网站的公司公司手机版网站模板
  • 河南国安建设集团有限公司信息网站如何进入网站
  • 网站建设框架模板下载建筑工程网库
  • 小学学校网站如何自己做小程序免费
  • 企业微信网站开发公司网站优化怎么做分录
  • 上海网站建设网页制杭州网络安全公司排名
  • 重庆h5建站模板钢球 东莞网站建设
  • 怎么在网上创建网站长沙企业网站建设哪家好
  • 网站 搭建 亚洲服务器自己可以做网站生意好做吗
  • 庆阳网站设计网站建设 图纸网
  • 怎样建立自己网站wordpress社交风格模板
  • 江西seo网站排名优化用wordpress写网页