最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android實現(xiàn)記住用戶名和密碼以及自動登錄

 更新時間:2019年09月09日 08:32:50   作者:子墨_  
這篇文章主要為大家詳細介紹了android實現(xiàn)記住用戶名和密碼以及自動登錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下

畢業(yè)剛開始上班接觸的第一個項目移動護士站,接到了第一任務(wù)就是登錄,要用到自動登錄功能,所以在這做個記錄,以后用的時候直接來粘貼復(fù)制,廢話少說,直奔主題

先上一下效果圖,由于只是實現(xiàn)功能,界面沒有美化,見諒

由于xml文件內(nèi)容,就不展現(xiàn)在這了,自己寫一寫就好,爸媽再也不用擔(dān)心我的學(xué)習(xí)了,so easy

package com.sdufe.login;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
 
/**
 * @author lili.guo
 *
 * 2014-6-6下午3:20:17
 */
public class MainActivity extends Activity {
 
 private EditText username_et;
 private EditText password_et;
 private CheckBox rem;
 private CheckBox auto;
 private Button login;
 private String username,password;
 SharedPreferences sp;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 sp=getSharedPreferences("userInfo",Context.MODE_WORLD_READABLE);
 
 username_et=(EditText) findViewById(R.id.username);
 password_et=(EditText) findViewById(R.id.password);
 rem=(CheckBox) findViewById(R.id.remember);
 auto=(CheckBox) findViewById(R.id.autologin);
 login=(Button) findViewById(R.id.login);
 
 if (rem.isChecked()) {
 
 username_et.setText(sp.getString("username", ""));
 password_et.setText(sp.getString("password", ""));
 
 if (auto.isChecked()) {
 Intent intent1=new Intent();
 intent1.setClass(getApplicationContext(), Welcome.class);
 startActivity(intent1);
 }
 
 }
 
 login.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 username=username_et.getText().toString();
 password=password_et.getText().toString();
 
 if (username.equals("Thea")&&password.equals("123")) {
  
  Toast.makeText(getApplicationContext(), "登錄成功", Toast.LENGTH_SHORT).show();
  
  if (rem.isChecked()) {
  Editor editor=sp.edit();
  editor.putString("username", username);
  editor.putString("password", password);
  editor.commit();
  }
  
  Intent intent2=new Intent();
  intent2.setClass(getApplicationContext(), Welcome.class);
  startActivity(intent2);
 }
 
 
 }
 });
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }
 
}

用戶名和密碼是寫死的,為了方便有需要的人學(xué)習(xí),稍微解釋一下

if (rem.isChecked()) {
 
 username_et.setText(sp.getString("username", ""));
 password_et.setText(sp.getString("password", ""));
 
 if (auto.isChecked()) {
 Intent intent1=new Intent();
 intent1.setClass(getApplicationContext(), Welcome.class);
 startActivity(intent1);
 }
 
 }

以上代碼意思是如果記住密碼就拿到本地存儲的用戶名和密碼,如果是自動登錄則直接跳轉(zhuǎn)的下一個網(wǎng)頁

if (rem.isChecked()) {
  Editor editor=sp.edit();
  editor.putString("username", username);
  editor.putString("password", password);
  editor.commit();
  }
  
  Intent intent2=new Intent();
  intent2.setClass(getApplicationContext(), Welcome.class);
  startActivity(intent2);

以上代碼意思是說如果是記住密碼的狀態(tài),則把用戶名和密碼寫到本地

注意一點哈,跳轉(zhuǎn)到下一個activity時,要修改一下AndroidManifest.xml文件,ok,結(jié)束。

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

相關(guān)文章

  • Kotlin如何直接使用控件ID原理詳析

    Kotlin如何直接使用控件ID原理詳析

    這篇文章主要給大家介紹了關(guān)于Kotlin如何直接使用控件ID原理的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • Kotlin?作用域函數(shù)apply、let、run、with、also使用指南

    Kotlin?作用域函數(shù)apply、let、run、with、also使用指南

    在?Kotlin?開發(fā)中,作用域函數(shù)(Scope?Functions)是一組能讓代碼更簡潔、更函數(shù)式的高階函數(shù),本文將結(jié)合核心特性、代碼示例和對比表格,助你精準(zhǔn)掌握apply、let、run、with、also的使用精髓,感興趣的朋友一起看看吧
    2025-04-04
  • Android仿新浪微博啟動界面或登陸界面(1)

    Android仿新浪微博啟動界面或登陸界面(1)

    這篇文章主要為大家詳細介紹了Android仿新浪微博啟動界面或登陸界面的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 淺談Android Dialog窗口機制

    淺談Android Dialog窗口機制

    本文主要介紹了Android Dialog窗口機制,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android圖像切換器imageSwitcher的實例應(yīng)用

    Android圖像切換器imageSwitcher的實例應(yīng)用

    這篇文章主要為大家詳細介紹了Android圖像切換器imageSwitcher的實例應(yīng)用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Android使用http請求手機號碼歸屬地查詢代碼分享

    Android使用http請求手機號碼歸屬地查詢代碼分享

    這篇文章主要介紹了Android使用http請求手機號碼歸屬地查詢代碼分享的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • Anroid ListView分組和懸浮Header實現(xiàn)方法

    Anroid ListView分組和懸浮Header實現(xiàn)方法

    這篇文章主要介紹了Anroid ListView分組和懸浮Header實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • android開發(fā)PathEffect問題處理

    android開發(fā)PathEffect問題處理

    本文主要整理了關(guān)于android中PathEffect的問題匯總以及處理方式,以及給大家做了關(guān)于PathEffect類的詳細解釋。
    2017-11-11
  • android自定義簡單時鐘

    android自定義簡單時鐘

    這篇文章主要為大家詳細介紹了android自定義簡單時鐘,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • Kotlin中Stack與LinkedList的實現(xiàn)方法示例

    Kotlin中Stack與LinkedList的實現(xiàn)方法示例

    這篇文章主要給大家介紹了關(guān)于Kotlin中Stack與LinkedList實現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06

最新評論

宜昌市| 麻栗坡县| 陈巴尔虎旗| 昌黎县| 平顺县| 福州市| 南木林县| 石门县| 额济纳旗| 甘孜县| 肥东县| 顺义区| 巩义市| 德江县| 唐河县| 南丹县| 车险| 丹阳市| 郎溪县| 忻城县| 修文县| 马尔康县| 科技| 牡丹江市| 平阳县| 大连市| 普兰县| 大理市| 拜城县| 高要市| 桦甸市| 尉犁县| 嘉鱼县| 洛扎县| 泊头市| 荥经县| 隆回县| 日喀则市| 望奎县| 兴宁市| 纳雍县|