亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android sharedPreferences實(shí)現(xiàn)記住密碼功能

 更新時(shí)間:2021年09月22日 15:37:35   作者:WQQDBK1  
這篇文章主要為大家詳細(xì)介紹了Android sharedPreferences實(shí)現(xiàn)記住密碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android sharedPreferences實(shí)現(xiàn)記住密碼功能,供大家參考,具體內(nèi)容如下

編寫界面交互代碼:

package com.example.bz0209.login;

import android.content.DialogInterface;
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.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
  private EditText username;
  private EditText password;
  private CheckBox ck;
  private SharedPreferences sharedPreferences;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();
    sharedPreferences=getSharedPreferences("remeberword",MODE_PRIVATE);
    Boolean isRemeber=sharedPreferences.getBoolean("remeberword",false);
    if(isRemeber) {
      String name=sharedPreferences.getString("name","");
      String pass=sharedPreferences.getString("pass","");
      username.setText(name);
      password.setText(pass);
      ck.setChecked(true);
    }
  }
  private void initView(){
    username=(EditText)findViewById(R.id.username);
    password=(EditText)findViewById(R.id.password);
    ck= (CheckBox) findViewById(R.id.ck);
  }
  private void login(View view){//在layout中設(shè)置onClick事件
    String name=username.getText().toString();
    String pass=password.getText().toString();
    if("admin".equals(name)&&"123".equals(pass)){
     SharedPreferences.Editor editor=sharedPreferences.edit();
      if(ck.isChecked()){
        editor.putBoolean("remeberword",true);
        editor.putString("name",name);
        editor.putString("pass",pass);
      }else{
        editor.clear();
      }
      editor.commit();
    }
  }
}

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

相關(guān)文章

最新評論