Loginactivity.java
PackageCom.example.ruian;Importandroid.app.Activity;ImportAndroid.app.AlertDialog;ImportAndroid.content.DialogInterface;Importandroid.content.Intent;Importandroid.content.SharedPreferences;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classLoginactivityextendsActivity {PrivateEditText M_txtusername =NULL; PrivateEditText m_txtpwd =NULL; PrivateButton m_butlogin=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_login); Findviews (); Setlistensers (); } Private voidfindviews () {m_txtusername=(EditText) Findviewbyid (r.id.txtusername); M_txtpwd=(EditText) Findviewbyid (R.ID.TXTPWD); M_butlogin=(Button) Findviewbyid (R.id.butlogin); } Private voidsetlistensers () {//Login ButtonM_butlogin.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {Butlogin_onclick (v); } }); } Private voidButlogin_onclick (View v) {//System ParametersSharedpreferences share = getsharedpreferences ("Perference", mode_private); //Login Password---------------------------------------------------------------String strloginpwd_value=share.getstring ("Login_pwd_value", "" "); //M_txtpwd.settext (strloginpwd_value); if(Strloginpwd_value.equals ("") = =true){//NULL to set the initial valueStrloginpwd_value=getresources (). getString (R.string.loginpwd_init);//Default login Password} String strloginpwd=M_txtpwd.gettext (). toString (); if(Strloginpwd.equals (strloginpwd_value) = =true){ //Landing Success//declare the intent object and start the loginactivity ActivityIntent Intent =NewIntent (); Intent.setclass (loginactivity. This, Mainactivity.class); StartActivity (Intent); //Deleting the current activity from the history stack will not return to the activity when the user taps the "back" button. finish (); } Else{OpenDialog ("Login Password Error!" "," message "); } } //The dialog box pops up-------------------------------------------------- Private voidOpenDialog (String strMsg, String strtitle) {NewAlertdialog.builder ( This). Settitle (strtitle). Setmessage (STRMSG). Setpositivebutton (Confirm, NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) { //TODO auto-generated Method Stub}}). Show (); } //pop Up confirmation, cancel dialog box-------------------------------------------------- Private voidOpendialogok (String strMsg, String strtitle) {NewAlertdialog.builder ( This). Settitle (strtitle). Setmessage (STRMSG). Setpositivebutton (Confirm, NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) { //TODO auto-generated Method StubOpenDialog ("Login password error!") -----"," message "); }}). Setnegativebutton (Cancel, NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) { //TODO auto-generated Method StubOpenDialog ("Login password error!") ===== "," message "); }}). Show (); } }
Activity_login.xml
<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <TableRow> <TextView android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:gravity= "Center"android:textsize= "20dip"Android:layout_weight= "1"Android:text= "User Login"/> </TableRow> <TableRow> <TextView Android:id= "@+id/lblusername"Android:layout_weight= "1"Android:text= "User name:"/> </TableRow> <TableRow> <EditText Android:id= "@+id/txtusername"Android:layout_weight= "1"Android:inputtype= "Textpassword" > </EditText> </TableRow> <TableRow> <TextView Android:id= "@+id/lblpwd"Android:layout_weight= "1"Android:text= "Password:"/> </TableRow> <TableRow> <EditText Android:id= "@+id/txtpwd"Android:layout_weight= "1"Android:inputtype= "Textpassword" > </EditText> </TableRow> <TableRow> <Button Android:id= "@+id/butlogin"Android:layout_weight= "1"Android:text= "Login"/> </TableRow></TableLayout>
Strings.xml
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "Loginpwd_init" >123456</ String></resources>
The most important step is to set this interface as the startup page.
Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.ruian"Android:versioncode= "1"Android:versionname= "1.0" > <uses-SDK Android:minsdkversion= "8"android:targetsdkversion= "/>" <Application Android:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <Activity Android:name= "Com.example.ruian.LoginActivity"Android:label= "@string/app_name" > <intent-filter> <action android:name= "Android.intent.action.MA In "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter& Gt </activity> <activity android:name= "parasetactivity" ></activity> <activity android:name = "Mainactivity" ></activity> </application></manifest>
Description
android:name= "com.example.ruian.LoginActivity" Loginactivity is the setting of the initial interface for the landing page.
<activity android:name= "parasetactivity" ></activity> This is the activity of setting up the interface
<activity android:name= "Mainactivity" ></activity> This is the activity of the main interface
Android Login Interface