The main implementation of login and remember password function
The main steps are as follows:
Login Function
1, Login.xml
STEP1: First establish drawable folder, create Logintopbg_roundcorner.xml
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#55FFFFFF"/> <corners android:radius= "15DP"/></shape>
STEP2: Create Btn_select.xml
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/btn_shape "android:state_pressed=" false "></item> <item android:drawable= "@drawable/btn_shape_after" android:state_pressed= "true" ></item></ Selector>
Where the Btn_shape.xml file and the Btn_shape_after.xml file are as follows
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#FF72CAE1" /> <corners android:radius= "10DP"/></ Shape>
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#87cefa"/> <corners android:radius= "10DP"/></shape>
STEP3: Define the Login_top.xml file with the following layout
<pre name= "code" class= "HTML" ><?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:background=" @drawable/btnbg_roundcorner "android:paddingbottom=" @dimen/activity_vertical_margin "Android:paddingleft=" @dimen/activity_horizontal_margin "android:paddingright=" @dimen/activity_horizontal_ Margin "android:paddingtop=" @dimen/activity_vertical_margin "> <textview android:id=" @+id/tvusername " Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentlef T= "true" android:layout_alignparenttop= "true" android:text= "@string/tvname" android:textappearance= "? Android:attr/textappearancemedium "/> <edittext android:id=" @+id/etusername "android:layout_width=" Match_parent "android:layout_height=" Wrap_contEnt "android:layout_alignleft=" @+id/tvusername "android:layout_below=" @+id/tvusername "android:backgr ound= "@android:d rawable/edit_text" android:ems= "> <requestfocus/> </EditText> < TextView android:id= "@+id/tvpassword" android:layout_width= "wrap_content" android:layout_height= "wrap _content "android:layout_alignleft=" @+id/etusername "android:layout_below=" @+id/etusername "android:t ext= "@string/tvpassword" android:textappearance= "Android:attr/textappearancemedium"/> <EditText A Ndroid:id= "@+id/etpassword" android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:layout_alignleft= "@+id/tvpassword" android:layout_below= "@+id/tvpassword" android:background= "@andro Id:drawable/edit_text "android:ems=" ten "android:inputtype=" Textpassword "/> <checkbox androi D:id= "@+id/cbrememberpasS "android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "Android:layout_alignbasel Ine= "@+id/btnlogin" android:layout_alignbottom= "@+id/btnlogin" android:layout_alignleft= "@+id/etPassword" android:text= "Remember Password" android:textsize= "20sp"/> <button android:id= "@+id/btnlogin" Andro Id:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignright= "@+id/etPasswo Rd "android:layout_below=" @+id/etpassword "android:background=" #FF72CAE1 "android:onclick=" Login " android:text= "@string/btnlogin"/></relativelayout>
2. activity_login.xml file
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:orientation= "vertical" android:background= "@drawable/loginbg" 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= ". Loginactivity "> <include layout=" @layout/login_top "/> <include layout=" @layout/login_ Bottom "/>" </LinearLayout>
3.activity_bottom.xml file
<?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 "> <textview androi D:id= "@+id/tvregist" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : layout_alignparentleft= "True" android:layout_alignparenttop= "true" android:layout_marginleft= "21DP" android:layout_margintop= "18DP" android:text= "@string/tvregister" android:autolink= "All" android:text colorlink= "#FF0066CC"/> <imageview android:id= "@+id/imageview1" android:layout_width= "wrap_content "Android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "Android:layout_alignpa Rentright= "true" android:layout_marginbottom= "24DP" android:src= "@drawable/panda"/> <imageview Android:id= "@+id/imageview2" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentbo Ttom= "true" android:layout_centerhorizontal= "true" android:layout_marginbottom= "28DP" android:src= "@d Rawable/icon "/></relativelayout>
4.loginActivity content is as follows
public class Loginactivity extends Activity {private EditText etusername;private EditText etpassword;private CheckBox CbI Srememberpass;private sharedpreferences sharedpreferences;private boolean rememberpassword; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_ TITLE); Setcontentview (R.layout.activity_login); Initviews (); Initvalues ();} @Overrideprotected void Onresume () {super.onresume (); if (Rememberpassword) {cbisrememberpass.setchecked (true); Etpassword.setonfocuschangelistener (New Onfocuschangelistener () {@Overridepublic void Onfocuschange (view view, Boolean flag) {if (flag) {String username = Etusername.gettext (). toString (); String savedusername = sharedpreferences.getstring ("username", "" "); if (Username.equals (Savedusername)) {string Password=sharedpreferences.getstring (username, ""); Etpassword.settext (password); Etpassword.setselection ( Password.length ());}}});}} private void Initvalues () {SharedpreferencES = Preferencemanager.getdefaultsharedpreferences (this); Rememberpassword = Sharedpreferences.getboolean (" Rememberpassword ", false);} private void Initviews () {etusername = (EditText) Findviewbyid (r.id.etusername); Etpassword = (EditText) Findviewbyid ( R.id.etpassword); cbisrememberpass = (CheckBox) Findviewbyid (R.id.cbrememberpass);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;} public void Login (view view) {}}
Data persistence Technology