Android实现登录界面记住密码的存储

  

Android存储方式有很多种,在这里所用的存储方式是SharedPreferrences,其采用了地图数据结构来存储数据,以键值的方式存储,可以简单的读取与写入。所以比较适合我们今天做的这个项目。我们来看一下运行图:

  

 Android实现登录界面记住密码的存储

  

<强>一。布局界面
  

  

1. login_top.xml         & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄?   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:填充=" @dimen/activity_horizontal_margin”   android:背景=癅drawable/logintop_roundbg”比;   EditText & lt;   android: id=癅 + id/etName”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: ems=" 10 "   android: drawablePadding=" 10 dp”   android:背景=" @android:可拉的/edit_text”   android: drawableLeft=" @drawable/icon_user”   android:提示=癅string/etName”比;   & lt; requestFocus> & lt;/requestFocus>   & lt;/EditText>   EditText & lt;   android: id=癅 + id/etPassword”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_below=" @ id/etName”   android: inputType=" textPassword "   android: ems=" 10 "   android: drawablePadding=" 10 dp”   android:背景=" @android:可拉的/edit_text”   android: drawableLeft=" @drawable/icon_pass”   android:提示=癅string/etpassword”比;   & lt; requestFocus> & lt;/requestFocus>   & lt;/EditText>   & lt;复选框   android: id=癅 + id/cbremenber”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_below=" @ id/etPassword”   android:文本=癅string/cbpass”/比;   LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_below=癅 id/cbremenber”比;   & lt;按钮   android: id=癅 + id/btnlogin”   android: layout_width=" 0 dp”   android: layout_height=" wrap_content "   android: layout_weight=" 1 "   android:背景=" @drawable/btnselect”   android:文本=" @string/btnlogin”   android: onClick="登录"/比;   & lt;按钮   android: id=癅 + id/btnRegister”   android: layout_width=" 0 dp”   android: layout_height=" wrap_content "   android: layout_weight=" 1 "   android:背景=" @drawable/btnselect”   android:文本=" @string/btnRegister”   android: layout_marginLeft=" 10 dp/比;   & lt;/LinearLayout>   & lt;/RelativeLayout>      之前      activity_main

2.。xml
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: id=癅 + id/activity_main”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android:背景=" @drawable/loginbg”   工具:上下文=癱n.edu.bzu.logindemo.MainActivity”比;      & lt;包括布局=癅layout/login_top”祝辞& lt;/include>      & lt; ImageView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:背景=" @drawable/鹿”   android: layout_alignParentBottom=" true "   android: layout_alignParentRight=" true "   android: layout_alignParentEnd=" true "/比;   & lt;/RelativeLayout>      之前      activity_welcome

3.。xml
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: id=癅 + id/activity_welcome”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   工具:上下文=癱n.edu.bzu.logindemo.WelcomeActivity”比;      & lt; TextView   android: id=癅 + id/tvwelcome”   android:文本=盎队恪?   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentTop=" true "   android: layout_centerHorizontal=" true "   android: layout_marginTop=" 200 dp”   android: textSize=" 40 sp”/比;   & lt;/RelativeLayout>      

Android实现登录界面记住密码的存储