Android實(shí)現(xiàn)記住密碼功能
本文實(shí)例為大家分享了Android實(shí)現(xiàn)記住密碼功能的具體代碼,供大家參考,具體內(nèi)容如下
LoginActivity.java
package com.wangdeqiang.www.chatwithrobot.BroadcastBestPractice; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import com.wangdeqiang.www.chatwithrobot.R; import static com.wangdeqiang.www.chatwithrobot.R.id.account; /** * @author */ public class LoginActivity extends BaseActivity { private SharedPreferences pref; private SharedPreferences.Editor editor; private EditText accountEdit; private EditText passwordEdit; private Button login; private CheckBox rememberPass; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); pref = PreferenceManager.getDefaultSharedPreferences(this); accountEdit = (EditText) findViewById(account); passwordEdit = (EditText) findViewById(R.id.password); rememberPass = (CheckBox) findViewById(R.id.remember_pass); login = (Button) findViewById(R.id.login); boolean isRemeber = pref.getBoolean("remember_password",false); if(isRemeber) { //將賬號和密碼都設(shè)置到文本框中 String account = pref.getString("account",""); String password = pref.getString("password",""); accountEdit.setText(account); passwordEdit.setText(password); rememberPass.setChecked(true); } login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String account = pref.getString("account", "").toString(); String password = pref.getString("password", "").toString(); //如果賬號和密碼是admin和123456,就認(rèn)為登陸成功 if (account.equals("admin") && password.equals("123456")) { editor = pref.edit(); if (rememberPass.isChecked()) { editor.putBoolean("remember", false); editor.putString("account", account); editor.putString("password", password); } else { editor.apply(); } editor.commit(); Intent intent = new Intent(LoginActivity.this, Main3Activity.class); startActivity(intent); finish(); } else { Toast.makeText(LoginActivity.this, "密碼或者賬號錯(cuò)誤", Toast.LENGTH_SHORT).show(); } } }); } }
activity_login.xml
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:orientation="horizontal"> <TextView android:layout_width="90dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="Account:" android:textSize="18sp" /> <EditText android:id="@+id/account" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:orientation="horizontal"> <TextView android:layout_width="90dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="Password" android:textSize="18sp" /> <EditText android:id="@+id/password" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:inputType="textPassword" /> </LinearLayout> </LinearLayout> <TableRow> <CheckBox android:id="@+id/remember_pass" android:layout_height="wrap_content" /> <TextView android:layout_height="wrap_content" android:text="Remeber password" /> </TableRow> <Button android:id="@+id/login" android:layout_height="wrap_content" android:layout_span="2" android:text="Login" /> </TableLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android SharedPreferences實(shí)現(xiàn)記住密碼和自動(dòng)登錄
- Android開發(fā)筆記SQLite優(yōu)化記住密碼功能
- Android實(shí)現(xiàn)用戶登錄記住密碼功能
- Android sharedPreferences實(shí)現(xiàn)記住密碼功能
- Android 使用SharedPreferrences儲存密碼登錄界面記住密碼功能
- Android實(shí)現(xiàn)登錄界面記住密碼的存儲
- Android SharedPreferences實(shí)現(xiàn)記住密碼和自動(dòng)登錄界面
- Android實(shí)現(xiàn)帶有記住密碼功能的登陸界面
- Android通過記住密碼功能學(xué)習(xí)數(shù)據(jù)存儲類SharedPreferences詳解及實(shí)例
- Android實(shí)現(xiàn)登陸界面的記住密碼功能
相關(guān)文章
Android中協(xié)調(diào)滾動(dòng)布局的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android中協(xié)調(diào)滾動(dòng)常用的布局實(shí)現(xiàn),類似這樣的協(xié)調(diào)滾動(dòng)布局,當(dāng)?shù)撞苛斜砘瑒?dòng)的時(shí)候,頂部的布局做響應(yīng)的動(dòng)作,我們都可以通過?AppBarLayout?和?MotionLayout?來實(shí)現(xiàn),本文通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2022-06-06Android 自定義ProgressDialog進(jìn)度條對話框用法詳解
ProgressDialog為進(jìn)度對話框。android手機(jī)自帶的對話框顯得比較單一,我們可以通過ProgressDialog來自己定義對話框中將要顯示出什么東西2016-01-01Android利用CircleImageView實(shí)現(xiàn)圓形頭像的方法
這篇文章主要介紹了Android利用CircleImageView實(shí)現(xiàn)圓形頭像的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10ContentProvider客戶端處理provider邏輯分析
這篇文章主要為大家介紹了ContentProvider客戶端處理provider邏輯分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11Android開發(fā)方式之Java+html+javascript混合開發(fā)
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)方式的其中一種Java+html+javascript混合開發(fā),感興趣的小伙伴們可以參考一下2016-06-06Android SQLite事務(wù)處理結(jié)合Listview列表顯示功能示例
這篇文章主要介紹了Android SQLite事務(wù)處理結(jié)合Listview列表顯示功能,較為詳細(xì)的分析了Android使用sqlite數(shù)據(jù)庫進(jìn)行事務(wù)操作并結(jié)合Listview進(jìn)行列表顯示的相關(guān)操作技巧,需要的朋友可以參考下2017-07-07android 使用OkHttp上傳多張圖片的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 使用OkHttp上傳多張圖片的相關(guān)資料,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-07-07Android View 完美實(shí)現(xiàn)EditText 在軟鍵盤上邊的示例
本篇文章主要介紹了Android View 完美實(shí)現(xiàn)EditText 在軟鍵盤上邊的示例,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08