中文JAVA技術平等自由協作創造

          Java專題文章博客和開源

          常用鏈接

          統計

          最新評論

          輸入密碼后自動登錄功能的實現

            今天在用某記賬軟件,我心里就再琢磨著,萬一被老婆拿到手機,胡亂翻一通,萬一看到了我的用錢流水賬,那可不好,要遭!我要隱私~怎么辦呢?于是發現其實人家早已想到,為用戶考慮到了這個問題,有個設置密碼功能,并且我發現啟動后,輸入密碼連以往的登錄或者進入進入的按鈕都沒有省去了,只要密碼輸入完匹配成功就自動進入了,好神奇,什么樣做的呢?這個設計,能減少用戶輸入,同時還有心思的設計是就算在沒有輸入密碼的時候也可以進行收入和支出的記錄,只是看不到詳細內容,非常好的設計!花了一點時間思考了一下就實現了這個小巧的自動登錄功能。

            下面把代碼貼上來吧,大蝦就勿噴了!

            LoginActivity.java

            [java]

            package com.challen;

            import android.app.Activity;

            import android.content.Intent;

            import android.os.Bundle;

            import android.text.Editable;

            import android.text.TextWatcher;

            import android.widget.EditText;

            import android.widget.TextView;

            /**

            * Activity which displays a login screen to the user, offering registration as

            * well.

            */

            public class LoginActivity extends Activity {

            private EditText mPasswordView;

            private TextView mLoginStatusMessageView;

            private Intent intent;

            @Override

            protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            mLoginStatusMessageView = (TextView)findViewById(R.id.sign_in_button);

            mPasswordView = (EditText) findViewById(R.id.password);

            mPasswordView.addTextChangedListener(new TextWatcher() {

            @Override

            public void onTextChanged(CharSequence s, int start, int before, int count) {

            if(mPasswordView.getText()。toString()。equals("123456")){

            intent = new Intent(LoginActivity.this,secondActivity.class);

            startActivity(intent);

            }

            }

            @Override

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override

            public void afterTextChanged(Editable s) {

            }

            });

            }

            @Override

            protected void onResume() {

            // 由于我知道你會點擊返回鍵反復試驗,所以加了這句話

            mPasswordView.setText("");

            super.onResume();

            }

            }

            跳轉過去的second.activity各位就隨便弄一個吧!不過需要記住的就是新增了activity后記著要在AndroidManifest.xml中添加這個activity托福答案

            mian.xml

            [html]

            <merge xmlns:android="schemas.android.com/apk/res/android"

            xmlns:tools="schemas.android.com/tools"

            tools:context=".LoginActivity" >

            <!-- Login form -->

            <LinearLayout

            style="@style/LoginFormContainer"

            android:orientation="vertical" >

            <EditText

            android:id="@+id/password"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:hint="輸入密碼"

            android:maxLines="1"

            android:singleLine="true" />

            <TextView

            android:id="@+id/sign_in_button"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="right"

            android:layout_marginTop="16dp"

            android:paddingLeft="32dp"

            android:paddingRight="32dp"

            android:text="密碼匹配成功則自動登錄" />

            </LinearLayout>

            </merge>

            其實最關鍵的就是知道edittext的一些監聽的函數了,例如還有一些自動補全特別是用于賬號輸入的時候,這里主要就是用到了監聽edittext的變化用到了addTextChangedListener,并且配合TextWatcher()就能實現在輸入的過程中進行一些操作了,把登錄跳轉的方法寫在了onTextChanged里北美托福答案

            好了,我這里預設的密碼就是123456設置死了的,大家可以試一試啦!

            延伸問題:

            1.這款記賬軟件設置的密碼就是保存在本地的,那么如何保存,讀取這個設置的密碼呢?(這個其實就設計到了本地數據的存儲,方法也多種多樣,后面有時間我們接著討論這個托福改分

            希望和大家多多交流,我也是android新兵,希望我們在這條路上堅持走下去,哪怕是一個小小的功能,只要能方便用戶,就會為我們增加更多的使用者和用戶。大家加油,積少成多,集腋成裘雅思答案

          posted on 2013-04-17 20:29 好不容易 閱讀(361) 評論(1)  編輯  收藏

          評論

          # re: 輸入密碼后自動登錄功能的實現 2013-04-18 09:03 mr ye

            if(mPasswordView.getText()。toString()。equals("123456"))代碼空指針異常的處理  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          PK10開獎 PK10開獎
          主站蜘蛛池模板: 民权县| 郸城县| 松原市| 广元市| 星座| 萨迦县| 潞西市| 囊谦县| 柘城县| 高阳县| 绥德县| 桐庐县| 保康县| 呼和浩特市| 开平市| 苏尼特右旗| 彰武县| 甘洛县| 屯留县| 平潭县| 德江县| 常州市| 平阴县| 平果县| 彭阳县| 乌拉特中旗| 色达县| 嘉鱼县| 贞丰县| 南部县| 宜宾县| 大田县| 丰台区| 拉萨市| 威信县| 徐汇区| 永川市| 永春县| 比如县| 安仁县| 甘谷县|