日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

利用android studio制作简单的QQ的注册、登录、忘记密码的页面

發布時間:2023/12/14 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用android studio制作简单的QQ的注册、登录、忘记密码的页面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、注冊頁面效果圖

?注冊的頁面布局;

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/k"tools:context=".MainActivity">//《-----------------歡迎標題---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:id="@+id/top"android:layout_width="275dp"android:layout_height="wrap_content"android:text="歡迎注冊QQ"android:textColor="@color/black"android:textSize="40dp" />></LinearLayout>//《-----------------注冊的昵稱設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/black"android:text="昵稱"android:textSize="40dp"/><EditTextandroid:id="@+id/name"android:layout_width="200dp"android:layout_height="match_parent"android:inputType="text"/></LinearLayout>//《-----------------注冊的密碼設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密碼"android:textColor="@color/black"android:textSize="40dp"/><EditTextandroid:id="@+id/password"android:layout_width="200dp"android:layout_height="match_parent"android:inputType="numberPassword"/></LinearLayout>//《-----------------注冊的手機號設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="手機號"android:textColor="@color/black"android:textSize="37dp"/><EditTextandroid:id="@+id/tele"android:inputType="number"android:layout_width="200dp"android:layout_height="wrap_content"/>></LinearLayout>//《-----------------注冊的同意協議---------------------》<RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="90dp"android:layout_marginTop="15dp"><RadioButtonandroid:id="@+id/xieyi"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="我已閱讀并同意相關服務條款和隱私政策 "android:textSize="15dp"/></RadioGroup>//《-----------------注冊的按鈕---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_gravity="center"android:layout_marginLeft="10dp"android:layout_marginTop="20dp"><Buttonandroid:id="@+id/register"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="立即注冊"app:backgroundTint="#786671"android:textSize="30dp" /></LinearLayout></LinearLayout>

注冊的實現(.java代碼)

package com.example.qq;import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;import android.content.SharedPreferences;import android.content.pm.ActivityInfo;import android.graphics.Color;import android.os.Bundle;//import android.support.v7.app.AppCompatActivity;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; //import cn.edu.gdmec.android.androidstudiodemo.utils.MD5Utils; import android.os.Bundle;public class RegisterActivity extends AppCompatActivity {private Button btn_register;//注冊按鈕//昵稱,密碼,手機號的控件private EditText et_user_name,et_psw,et_user_telep;//用戶名,密碼,再次輸入的密碼的控件的獲取值private String userName,psw,telep,xieyi;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_register);//設置頁面布局 ,注冊界面setContentView(R.layout.activity_register);//設置此界面為豎屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);init();}private void init() { //從activity_register.xml 頁面中獲取對應的UI控件btn_register=findViewById(R.id.register);et_user_name=findViewById(R.id.name);et_psw=findViewById(R.id.password);et_user_telep=findViewById(R.id.tele);//注冊按鈕btn_register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//獲取輸入在相應控件中的字符串getEditString();//判斷輸入框內容if (TextUtils.isEmpty(userName)) {Toast.makeText(RegisterActivity.this, "請輸入用戶名", Toast.LENGTH_SHORT).show();return;} else if (TextUtils.isEmpty(psw)) {Toast.makeText(RegisterActivity.this, "請輸入密碼", Toast.LENGTH_SHORT).show();return;} else if (TextUtils.isEmpty(telep)) {Toast.makeText(RegisterActivity.this, "請輸入手機號", Toast.LENGTH_SHORT).show();return;}/***從SharedPreferences中讀取輸入的用戶名,判斷SharedPreferences中是否有此用戶名*/else if (isExistUserName(userName)) {Toast.makeText(RegisterActivity.this, "此賬戶名已經存在", Toast.LENGTH_SHORT).show();return;} else {Toast.makeText(RegisterActivity.this, "注冊成功", Toast.LENGTH_SHORT).show();//把賬號、密碼和賬號標識保存到sp里面/*** 保存賬號和密碼到SharedPreferences中*/saveRegisterInfo(userName, psw);//注冊成功后把賬號傳遞到LoginActivity.java中// 返回值到loginActivity顯示Intent data = new Intent();data.putExtra("userName", userName);setResult(RESULT_OK, data);//RESULT_OK為Activity系統常量,狀態碼為-1,// 表示此頁面下的內容操作成功將data返回到上一頁面,如果是用back返回過去的則不存在用setResult傳遞dataRegisterActivity.this.finish(); } }});}/*** 獲取控件中的字符串*/private void getEditString() {userName = et_user_name.getText().toString().trim();psw = et_psw.getText().toString().trim();telep = et_user_telep.getText().toString().trim();}/*** 從SharedPreferences中讀取輸入的用戶名,判斷SharedPreferences中是否有此用戶名*/private boolean isExistUserName(String userName) {boolean has_userName = false;//mode_private SharedPreferences sp = getSharedPreferences( );// "loginInfo", MODE_PRIVATESharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE);//獲取密碼String spPsw = sp.getString(userName, "");//傳入用戶名獲取密碼//如果密碼不為空則確實保存過這個用戶名if (!TextUtils.isEmpty(spPsw)) {has_userName = true;}return has_userName;}/*** 保存賬號和密碼到SharedPreferences中SharedPreferences*/private void saveRegisterInfo(String userName, String psw) {//loginInfo表示文件名, mode_private SharedPreferences sp = getSharedPreferences( );SharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE);//獲取編輯器, SharedPreferences.Editor editor -> sp.edit();SharedPreferences.Editor editor = sp.edit();//提交修改 editor.commit();editor.commit();}}

二、登錄頁面效果圖

?登錄的頁面布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/i"tools:context=".MainActivity">//《-----------------頭像設計---------------------》<LinearLayoutandroid:layout_width="100dp"android:layout_height="100dp"android:layout_centerHorizontal="true"android:layout_marginTop="40dp"android:layout_gravity="center"android:background="@drawable/head"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="40dp" /><EditTextandroid:id="@+id/top"android:layout_width="200dp"android:layout_height="match_parent" /></LinearLayout>//《-----------------賬號設計---------------------》<LinearLayoutandroid:id="@+id/ID"android:layout_width="match_parent"android:layout_height="82dp"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:layout_marginTop="15dp"android:layout_marginRight="10dp"android:layout_marginBottom="5dp"android:orientation="horizontal">//文本框<TextViewandroid:id="@+id/tv_ID"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="賬號:"android:textColor="#000"android:textSize="30sp" />//編輯文本<EditTextandroid:id="@+id/et_ID"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="5dp"android:layout_toRightOf="@id/et_ID"android:background="@null"android:inputType="text"android:padding="10dp" /></LinearLayout>//《-----------------密碼設計---------------------》<LinearLayoutandroid:id="@+id/password"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/password"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:orientation="horizontal">//文本框<TextViewandroid:id="@+id/tv_password"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="密碼:"android:textColor="#000"android:textSize="30sp" />//編輯文本<EditTextandroid:id="@+id/et_password"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="5dp"android:layout_toRightOf="@id/tv_password"android:background="@null"android:inputType="textPassword"android:padding="10dp" /></LinearLayout>//《-----------------登錄按鈕設計---------------------》<Buttonandroid:id="@+id/btn_login"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="70dp"android:text="登錄"android:textColor="#ffffff"android:background="#3C8DC4"android:textSize="30sp"app:backgroundTint="#EBA7CF"android:layout_below="@+id/btn_login"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"/>//《-----------------注冊忘記密碼設計---------------------》<LinearLayoutandroid:id="@+id/b"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="30dp"android:orientation="horizontal"><Buttonandroid:id="@+id/b1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注冊"app:backgroundTint="#EDD5E3"android:textSize="30dp" /><Buttonandroid:id="@+id/b2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="140dp"android:text="忘記密碼"android:textSize="30dp"app:backgroundTint="#EDD5E3" /></LinearLayout></LinearLayout>

登錄的實現(.java代碼)

package com.example.qq; import android.content.Intent; import androidx.appcompat.app.AppCompatActivity; import android.content.SharedPreferences;import android.content.pm.ActivityInfo;import android.os.Bundle;//import android.support.v7.app.AppCompatActivity;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;//import cn.edu.gdmec.android.androidstudiodemo.utils.MD5Utils;public class MainActivity extends AppCompatActivity {//顯示的注冊,找回密碼private TextView tv_register,tv_find_psw;//登錄按鈕private Button btn_login;//獲取的用戶名,密碼private String userName,psw;//賬號,密碼的編輯框private EditText et_user_name,et_psw;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//設置此界面為豎屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);init();}//獲取界面控件private void init() {//從activity_main.xml中獲取的tv_register = findViewById(R.id.b1);//注冊的IDtv_find_psw = findViewById(R.id.b2);//找回密碼的IDbtn_login = findViewById(R.id.btn_login);//登錄按鈕et_user_name = findViewById(R.id.et_ID);//賬號et_psw = findViewById(R.id.et_password);//密碼//立即注冊控件的點擊事件tv_register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//為了跳轉到注冊界面,并實現注冊功能Intent intent=new Intent(MainActivity.this,RegisterActivity.class);startActivityForResult(intent, 1);}});//找回密碼控件的點擊事件tv_find_psw.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//跳轉到找回密碼界面(此頁面暫未創建)Intent intent=new Intent(MainActivity.this,LostfoundActivity.class);startActivityForResult(intent, 1);}});//登錄按鈕的點擊事件btn_login.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//開始登錄,獲取用戶名和密碼 getText().toString().trim();userName=et_user_name.getText().toString().trim();psw=et_psw.getText().toString().trim();//對當前用戶輸入的密碼進行MD5加密再進行比對判斷, MD5Utils.md5( ); psw 進行加密判斷是否一致// String md5Psw= MD5Utils.md5(psw);// md5Psw ; spPsw 為 根據從SharedPreferences中用戶名讀取密碼// 定義方法 readPsw為了讀取用戶名,得到密碼// spPsw=readPsw(userName);// TextUtils.isEmptyif(TextUtils.isEmpty(userName)){Toast.makeText(MainActivity.this, "請輸入用戶名", Toast.LENGTH_SHORT).show();return;}else if(TextUtils.isEmpty(psw)) {Toast.makeText(MainActivity.this, "請輸入密碼", Toast.LENGTH_SHORT).show();return;}else{ //此用戶名不存在Toast.makeText(MainActivity.this, "登錄成功", Toast.LENGTH_SHORT).show();}}});}/***從SharedPreferences中根據用戶名讀取密碼*/private String readPsw(String userName){//getSharedPreferences("loginInfo",MODE_PRIVATE);//"loginInfo",mode_private; MODE_PRIVATE表示可以繼續寫入SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);//sp.getString() userName, "";return sp.getString(userName , "");}/***保存登錄狀態和登錄用戶名到SharedPreferences中*/private void saveLoginStatus(boolean status,String userName){//saveLoginStatus(true, userName);//loginInfo表示文件名 SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);//獲取編輯器SharedPreferences.Editor editor=sp.edit();//存入boolean類型的登錄狀態editor.putBoolean("isLogin", status);//存入登錄狀態時的用戶名editor.putString("loginUserName", userName);//提交修改editor.commit();}/*** 注冊成功的數據返回至此* @param requestCode 請求碼* @param resultCode 結果碼* @param data 數據*/@Override//顯示數據, onActivityResult//startActivityForResult(intent, 1); 從注冊界面中獲取數據//int requestCode , int resultCode , Intent data// LoginActivity -> startActivityForResult -> onActivityResult();protected void onActivityResult(int requestCode, int resultCode, Intent data) {//super.onActivityResult(requestCode, resultCode, data);super.onActivityResult(requestCode, resultCode, data);if(data!=null){//是獲取注冊界面回傳過來的用戶名// getExtra().getString("***");String userName=data.getStringExtra("userName");if(!TextUtils.isEmpty(userName)){//設置用戶名到 et_user_name 控件et_user_name.setText(userName);//et_user_name控件的setSelection()方法來設置光標位置et_user_name.setSelection(userName.length());}}}}

三、忘記密碼頁面效果圖

?忘記密碼的頁面布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/k"tools:context=".MainActivity">//《-----------------歡迎標題---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:id="@+id/top"android:layout_width="275dp"android:layout_height="wrap_content"android:text="歡迎注冊QQ"android:textColor="@color/black"android:textSize="40dp" />></LinearLayout>//《-----------------注冊的昵稱設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/black"android:text="昵稱"android:textSize="40dp"/><EditTextandroid:id="@+id/name"android:layout_width="200dp"android:layout_height="match_parent"android:inputType="text"/></LinearLayout>//《-----------------注冊的密碼設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密碼"android:textColor="@color/black"android:textSize="40dp"/><EditTextandroid:id="@+id/password"android:layout_width="200dp"android:layout_height="match_parent"android:inputType="numberPassword"/></LinearLayout>//《-----------------注冊的手機號設置---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="手機號"android:textColor="@color/black"android:textSize="37dp"/><EditTextandroid:id="@+id/tele"android:inputType="number"android:layout_width="200dp"android:layout_height="wrap_content"/>></LinearLayout>//《-----------------注冊的同意協議---------------------》<RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="90dp"android:layout_marginTop="15dp"><RadioButtonandroid:id="@+id/xieyi"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="我已閱讀并同意相關服務條款和隱私政策 "android:textSize="15dp"/></RadioGroup>//《-----------------注冊的按鈕---------------------》<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_gravity="center"android:layout_marginLeft="10dp"android:layout_marginTop="20dp"><Buttonandroid:id="@+id/register"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="立即注冊"app:backgroundTint="#786671"android:textSize="30dp" /></LinearLayout></LinearLayout>

忘記密碼的實現(.java)

package com.example.qq;import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;import android.content.SharedPreferences;import android.content.pm.ActivityInfo;import android.graphics.Color;import android.os.Bundle;//import android.support.v7.app.AppCompatActivity;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast;//import cn.edu.gdmec.android.androidstudiodemo.utils.MD5Utils;public class LostfoundActivity extends AppCompatActivity {//重置密碼按鈕private Button btn_register;//用戶名,密碼,再次輸入的密碼,電話,驗證碼的控件private EditText et_user_name,et_psw,et_psw_again,et_user_tele,et_user_code;//用戶名,密碼,再次輸入的密碼,電話,驗證碼的控件的獲取值private String userName,psw,pswAgain,userTele,userCode;//標題布局private RelativeLayout rl_title_bar;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//設置頁面布局 ,注冊界面setContentView(R.layout.activity_lostfound);//設置此界面為豎屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);init(); }private void init() {//從activity_lostfound.xml 頁面布局中獲取對應的UI控件et_user_name=findViewById(R.id.username);et_psw_again=findViewById(R.id.password2);et_user_tele=findViewById(R.id.tele);et_psw=findViewById(R.id.password1);et_user_code=findViewById(R.id.Code);btn_register=findViewById(R.id.bt);//重置按鈕btn_register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//獲取輸入在相應控件中的字符串getEditString();//判斷輸入框內容if(TextUtils.isEmpty(userName)){Toast.makeText(LostfoundActivity.this, "請輸入用戶名", Toast.LENGTH_SHORT).show();return;} else if(TextUtils.isEmpty(psw)){Toast.makeText(LostfoundActivity.this, "請輸入密碼", Toast.LENGTH_SHORT).show();return;}else if(TextUtils.isEmpty(pswAgain)){Toast.makeText(LostfoundActivity.this, "請再次輸入密碼", Toast.LENGTH_SHORT).show();return;}//驗證碼,手機號驗證空有問題//else if(TextUtils.isEmpty(userTele)){//Toast.makeText(LostfoundActivity.this, "請輸入手機號", Toast.LENGTH_SHORT).show();//return;}//else if(TextUtils.isEmpty(userCode)){// Toast.makeText(LostfoundActivity.this, "請輸入驗證碼", Toast.LENGTH_SHORT).show();//return;//}else if(!psw.equals(pswAgain)){Toast.makeText(LostfoundActivity.this, "輸入兩次的密碼不一樣", Toast.LENGTH_SHORT).show();return;} else if(isExistUserName(userName)){Toast.makeText(LostfoundActivity.this, "此賬戶名已經存在", Toast.LENGTH_SHORT).show();return;}else{Toast.makeText(LostfoundActivity.this, "密碼重置成功", Toast.LENGTH_SHORT).show();//把賬號、密碼和賬號標識保存到sp里面/*** 保存賬號和密碼到SharedPreferences中*/saveRegisterInfo(userName, psw);//注冊成功后把賬號傳遞到registerActivity.java中// 返回值到mainActivity顯示Intent data = new Intent();data.putExtra("userName", userName);setResult(RESULT_OK, data);//RESULT_OK為Activity系統常量,狀態碼為-1,// 表示此頁面下的內容操作成功將data返回到上一頁面,如果是用back返回過去的則不存在用setResult傳遞data值LostfoundActivity.this.finish();}}});}/*** 獲取控件中的字符串*/private void getEditString(){userName=et_user_name.getText().toString().trim();psw=et_psw.getText().toString().trim();pswAgain=et_psw_again.getText().toString().trim();}/*** 從SharedPreferences中讀取輸入的用戶名,判斷SharedPreferences中是否有此用戶名*/private boolean isExistUserName(String userName){boolean has_userName=false;//mode_private SharedPreferences sp = getSharedPreferences( );// "loginInfo", MODE_PRIVATESharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);//獲取密碼String spPsw=sp.getString(userName, "");//傳入用戶名獲取密碼//如果密碼不為空則確實保存過這個用戶名if(!TextUtils.isEmpty(spPsw)) {has_userName=true;}return has_userName;}/*** 保存賬號和密碼到SharedPreferences中SharedPreferences*/private void saveRegisterInfo(String userName,String psw){// String md5Psw = MD5Utils.md5(psw);//把密碼用MD5加密//loginInfo表示文件名, mode_private SharedPreferences sp = getSharedPreferences( );SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);//獲取編輯器, SharedPreferences.Editor editor -> sp.edit();SharedPreferences.Editor editor=sp.edit();//以用戶名為key,密碼為value保存在SharedPreferences中//key,value,如鍵值對,editor.putString(用戶名,密碼);// editor.putString(userName, md5Psw);//提交修改 editor.commit();editor.commit();}}

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的利用android studio制作简单的QQ的注册、登录、忘记密码的页面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。