欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)用戶登錄記住密碼功能

 更新時間:2017年05月19日 14:09:19   作者:愛吃蛋糕的南宮滕逸  
這篇文章主要為大家詳細介紹了Android實現(xiàn)用戶登錄記住密碼功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、打開之前完成的Case_login進行修改再編輯

二、將注冊按鈕刪除并在登錄按鈕前拖出一個checkBox,編輯代碼如下:

在layout_top.xml文件中進行編輯

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:padding="@dimen/activity_horizontal_margin"
 android:background="@drawable/logintop_roundbg">

 <EditText
  android:id="@+id/etName"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@android:drawable/edit_text"
  android:drawableLeft="@drawable/icon_user"
  android:drawablePadding="10dp"
  android:ems="10"
  android:hint="@string/etName">

  <requestFocus />
 </EditText>

 <EditText
  android:id="@+id/etPassword"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@id/etName"
  android:background="@android:drawable/edit_text"
  android:drawableLeft="@drawable/icon_pass"
  android:drawablePadding="10dp"
  android:ems="10"
  android:hint="@string/etPass"
  android:inputType="textPassword">

  <requestFocus />
 </EditText>

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/etPassword">

  <Button
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/btn_select"
   android:text="@string/btnLogin" />

  <Button
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:layout_marginLeft="10dp"
   android:background="@drawable/btn_select"
   android:text="@string/btnRegister" />

 </LinearLayout>
</RelativeLayout>

效果圖如下:

三、對登錄密碼及記住密碼進行編輯

在LoginAcitvity.java文件進行編寫修改,代碼如下:

package cn.edu.bzu.case_login;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {
 private EditText etName;
 private EditText etPassword;
 private CheckBox cbIsRememberPass;
 private SharedPreferences sharedPreferences;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_login);
  initViews();
  sharedPreferences=getSharedPreferences("rememberpassword", Context.MODE_PRIVATE);
  boolean isRemember=sharedPreferences.getBoolean("rememberpassword",false);
  if(isRemember){
   String name=sharedPreferences.getString("name","");
   String password=sharedPreferences.getString("password","");
   etName.setText(name);
   etPassword.setText(password);
   cbIsRememberPass.setChecked(true);


  }

 }
 private void initViews(){
  etName=(EditText)findViewById(R.id.etName);
  etPassword=(EditText)findViewById(R.id.etPassword);
  cbIsRememberPass=(CheckBox) findViewById(R.id.cbIsRememberPass);

 }
 public void login(View view){
  String name=etName.getText().toString();
  String password=etPassword.getText().toString();
  if("admin".equals(name)&&"123456".equals(password)){
   SharedPreferences.Editor editor=sharedPreferences.edit();
   if(cbIsRememberPass.isChecked()){
    editor.putBoolean("rememberpassword",true);
    editor.putString("name",name);
    editor.putString("password",password);

   }
   else {
    editor.clear();
   }
   editor.commit();
   Intent intent=new Intent(this,MainActivity.class);
   startActivity(intent);
   finish();
  }
  else {
   Toast.makeText(this,"賬戶或密碼錯誤",Toast.LENGTH_LONG).show();
  }

 }

}

四、設(shè)計登錄后的界面

新建一個MainActivity.java文件,同時生成一個activity_main.xml,對其進行編寫代碼效果圖如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="cn.edu.bzu.case_login.MainActivity">

 <TextView
  android:text="Welcome you"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerVertical="true"
  android:layout_centerHorizontal="true"
  android:textSize="40sp"
  android:id="@+id/textView" />
</RelativeLayout>

五、結(jié)果演示

再次打開軟件密碼就記住了如圖:


輸入錯誤的密碼有提示如下圖:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android?scrollview頂部漸漸消失實現(xiàn)實例詳解

    android?scrollview頂部漸漸消失實現(xiàn)實例詳解

    這篇文章主要為大家介紹了android?scrollview頂部漸漸消失實現(xiàn)實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-11-11
  • 加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout

    加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout

    AndroidProgressLayout實現(xiàn)為界面添加圓形進度條。調(diào)用setprogress()方法顯示和隱藏進度條,這篇文章主要介紹了加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout的相關(guān)資料,需要的朋友可以參考下
    2015-11-11
  • Android中實現(xiàn)詞組高亮TextView方法示例

    Android中實現(xiàn)詞組高亮TextView方法示例

    高亮顯示大家應(yīng)該都不陌生,在開發(fā)中經(jīng)常會遇到這個需求,所以下面這篇文章主要給大家介紹了關(guān)于Android中實現(xiàn)詞組高亮TextView的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-10-10
  • Android文字匹配度算法及實際應(yīng)用示例

    Android文字匹配度算法及實際應(yīng)用示例

    本文介紹了Android應(yīng)用中常用的文字匹配度算法Levenshtein Distance,并給出了實際應(yīng)用示例,通過合理選擇和應(yīng)用文字匹配度算法,可以實現(xiàn)多種功能,提升用戶體驗,增強應(yīng)用的實用性,需要的朋友可以參考下
    2024-05-05
  • Android 自定義日期段選擇控件功能(開始時間-結(jié)束時間)

    Android 自定義日期段選擇控件功能(開始時間-結(jié)束時間)

    這篇文章主要介紹了Android 自定義日期段選擇控件功能,開始時間-結(jié)束時間。本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • 淺談Android中Drawable使用知識總結(jié)

    淺談Android中Drawable使用知識總結(jié)

    本篇文章主要介紹了淺談Android中Drawable使用知識總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Android實現(xiàn)滑動到頂部懸停的效果

    Android實現(xiàn)滑動到頂部懸停的效果

    這篇文章給大家介紹一種不常見的實現(xiàn)Android滑動到頂部懸停效果的方式,對大家開發(fā)Android具有一定的參考借鑒價值,有需要的朋友們可以來一起看看。
    2016-09-09
  • Android中內(nèi)存泄漏需要的注意點

    Android中內(nèi)存泄漏需要的注意點

    在本篇文章里小編給大家整理了關(guān)于Android中內(nèi)存泄漏需要的注意點的相關(guān)內(nèi)容,有此需要的朋友們參考下。
    2019-06-06
  • Android高級組件AutoCompleteTextView自動完成文本框使用詳解

    Android高級組件AutoCompleteTextView自動完成文本框使用詳解

    這篇文章主要介紹了Android高級組件AutoCompleteTextView自動完成文本框的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android自定義控件之仿優(yōu)酷菜單

    Android自定義控件之仿優(yōu)酷菜單

    這篇文章主要為大家詳細介紹了Android自定義控件之仿優(yōu)酷菜單的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-06-06

最新評論