LoginActivity.java

package com.example.ruian; import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;public class LoginActivity extends Activity {        private EditText m_txtUserName = null;    private EditText m_txtPwd = null;    private Button m_butLogin=null;         @Override     protected void onCreate(Bundle savedInstanceState) {      // TODO Auto-generated method stub      super.onCreate(savedInstanceState);      setContentView(R.layout.activity_login);                findViews();        setListensers();                     }          private void findViews(){         m_txtUserName=(EditText) findViewById(R.id.txtUserName);           m_txtPwd=(EditText) findViewById(R.id.txtPwd);           m_butLogin = (Button) findViewById(R.id.butLogin);      }          private void setListensers(){         //Login按钮         m_butLogin.setOnClickListener(new View.OnClickListener() {             public void onClick(View v) {                 butLogin_OnClick(v);             }         });      }          private void butLogin_OnClick(View v){           //系统参数         SharedPreferences share = getSharedPreferences("perference",MODE_PRIVATE);         //登陆密码---------------------------------------------------------------         String strLoginPwd_value=share.getString("login_pwd_value","");         //m_txtPwd.setText(strLoginPwd_value);         if(strLoginPwd_value.equals("")==true){//为空则设初始值             strLoginPwd_value=getResources().getString(R.string.loginpwd_init);//默认登陆密码         }                  String strLoginPwd=m_txtPwd.getText().toString();         if(strLoginPwd.equals(strLoginPwd_value)==true){             //登陆成功              //声明Intent对象,并启动 LoginActivity Activity             Intent intent = new Intent();             intent.setClass(LoginActivity.this, MainActivity.class);              startActivity(intent);             //从历史堆栈中删除当前Activity,用户点击“返回”按钮键时,不会再返回到这个Activity。             finish();         }         else{             openDialog("登陆密码错误!","消息");         }     }          //弹出对话框--------------------------------------------------         private void openDialog(String strMsg, String strTitle){             new AlertDialog.Builder(this)                 .setTitle(strTitle)                 .setMessage(strMsg)                 .setPositiveButton("确认",                         new DialogInterface.OnClickListener() {                             @Override                             public void onClick(DialogInterface dialog, int which) {                                 // TODO Auto-generated method stub                             }                 })                 .show();         }                  //弹出确认、取消 对话框--------------------------------------------------         private void openDialogOk(String strMsg, String strTitle){             new AlertDialog.Builder(this)                 .setTitle(strTitle)                 .setMessage(strMsg)                 .setPositiveButton("确认",                         new DialogInterface.OnClickListener() {                             @Override                             public void onClick(DialogInterface dialog, int which) {                                 // TODO Auto-generated method stub                                 openDialog("登陆密码错误!-----","消息");                             }                 })                 .setNegativeButton("取消",                         new DialogInterface.OnClickListener() {                             @Override                             public void onClick(DialogInterface dialog, int which) {                                 // TODO Auto-generated method stub                                 openDialog("登陆密码错误!=====","消息");                             }                 })                 .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="用户登陆" />    </TableRow>     <TableRow>        <TextView            android:id="@+id/lblUserName"            android:layout_weight="1"            android:text="用户名:" />    </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="密码:" />    </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="登陆" />                 </TableRow></TableLayout>

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources>        <string name="loginpwd_init">123456</string></resources>

最重要的一步,将此界面设置为启动页。

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="17" />    <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.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity android:name="ParaSetActivity"></activity>        <activity android:name="MainActivity"></activity>    </application></manifest>

说明:

android:name="com.example.ruian.LoginActivity"  这句中的 LoginActivity 即是设置初始界面为登陆页。
<activity android:name="ParaSetActivity"></activity>  这句是设置界面的activity
<activity android:name="MainActivity"></activity> 这句是主界面的activity

更多相关文章

  1. android 滑动欢迎界面
  2. Android常用方法总结
  3. Android(安卓)主界面 九宫格 超灵活的配置
  4. android - 确认订单页面【仿】京东App
  5. Android(安卓)监听Fragment界面的点击事件
  6. android 模拟软件启动界面
  7. Andoid - 开发实例(2): ViewPager卡片式界面2
  8. android用户界面之AlarmManager教程实例汇
  9. android界面xml文件中导入另一个xml文件的方法include

随机推荐

  1. 【转】android:minSdkVersion 相关知识
  2. 自定义ListView中的分割线(转)
  3. Android中的多击事件
  4. Android(安卓)Native代码中的status_t定
  5. Android开发学习之Animation之Android帧
  6. Unity3d Android开发 Android(安卓)Devel
  7. 【Android经典入门教程-下(bill译)】
  8. AsyncTask机制详解
  9. windows中android SDK manager安装更新sd
  10. android中使用MediaPlayer播放视频