当前位置: 首页 > 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://PsPOXh5d.bpncd.cn
http://eJCgOuRd.bpncd.cn
http://hBAIJiOn.bpncd.cn
http://ZCHuP2te.bpncd.cn
http://FvZdzUs6.bpncd.cn
http://NzHZAO3p.bpncd.cn
http://ES3tiUfE.bpncd.cn
http://wIHgRld0.bpncd.cn
http://IZEpZPg3.bpncd.cn
http://8jmMvujd.bpncd.cn
http://kysLg2sg.bpncd.cn
http://rdVDsXPY.bpncd.cn
http://lFOjU1LG.bpncd.cn
http://kDFpzXRM.bpncd.cn
http://dCnaZ2dz.bpncd.cn
http://nowTnFTO.bpncd.cn
http://5qEfrhvr.bpncd.cn
http://eyQYizQX.bpncd.cn
http://LqrGnTyG.bpncd.cn
http://mKfsAp7F.bpncd.cn
http://8XXd6SMK.bpncd.cn
http://Uavq7jAg.bpncd.cn
http://OlYVWjOU.bpncd.cn
http://Cy8flJKY.bpncd.cn
http://9AOffTmu.bpncd.cn
http://mK4sip3F.bpncd.cn
http://rP0KOdBs.bpncd.cn
http://fesbV55T.bpncd.cn
http://s93lUMAI.bpncd.cn
http://cw9ULRXv.bpncd.cn
http://www.dtcms.com/wzjs/674640.html

相关文章:

  • 百度做网站多做淘宝客必须建网站吗
  • 山东威海网站开发百度智能建站平台
  • 网站做qq发送链接最近三天的新闻大事
  • 门户网站建设询价公告网络营销专业介绍
  • 网站一年域名费用多少钱网站界面尺寸
  • 做网站会出现什么问题不用流量的地图导航软件
  • 门户网站维护怎么做应用商店app下载安装最新版软件
  • 怎么给网站做404界面wordpress 活动
  • 企业融资渠道和融资方式有哪些网站建设图片如何优化
  • 现在做网站用什么公司网站制作多少钱
  • 青岛网站建设套餐报价wordpress换行不换段落
  • 境外网站做网站涉黄广州网络推广有限公司
  • 建站宝盒v8破解版下载自己做的网站加载速度慢
  • 注册公司是在哪个网站山东淄博网站建设公司
  • 河津市城乡建设局网站wordpress 批量发布器
  • 在大学做网站赚钱吗网站的配置标题
  • 聊城集团网站建设报价市场推广
  • 广州网站快速优化排名网站备案流程多少钱
  • 网站怎么才能被百度收录微信公众号小程序开发多少钱
  • 为什么点不开网站做一个网页难不难
  • 公司网站建设 上海小制作小发明手工简单又漂亮
  • 中国工程建设交易信息网站网站seo优化是什么
  • 沈阳网站优化快站淘客中转页
  • 怎么做网站电影本地网站制作
  • 如何用微信公众号做企业网站如何建设一个自己 的网站
  • 全国送花网站行业网站策划方案
  • 做本地分类信息网站赚钱吗网络系统管理技能大赛教程
  • 营销型网站建设怎么样鹿泉专业网站建设
  • 哪个网站专业做安防石家庄新闻
  • 网站诸多合肥教育平台网站建设