今天在用某記賬軟件,我心里就再琢磨著,萬一被老婆拿到手機(jī),胡亂翻一通,萬一看到了我的用錢流水賬,那可不好,要遭!我要隱私~怎么辦呢?于是發(fā)現(xiàn)其實(shí)人家早已想到,為用戶考慮到了這個(gè)問題,有個(gè)設(shè)置密碼功能,并且我發(fā)現(xiàn)啟動(dòng)后,輸入密碼連以往的登錄或者進(jìn)入進(jìn)入的按鈕都沒有省去了,只要密碼輸入完匹配成功就自動(dòng)進(jìn)入了,好神奇,什么樣做的呢?這個(gè)設(shè)計(jì),能減少用戶輸入,同時(shí)還有心思的設(shè)計(jì)是就算在沒有輸入密碼的時(shí)候也可以進(jìn)行收入和支出的記錄,只是看不到詳細(xì)內(nèi)容,非常好的設(shè)計(jì)!花了一點(diǎn)時(shí)間思考了一下就實(shí)現(xiàn)了這個(gè)小巧的自動(dòng)登錄功能。
下面把代碼貼上來吧,大蝦就勿噴了!
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() {
// 由于我知道你會(huì)點(diǎn)擊返回鍵反復(fù)試驗(yàn),所以加了這句話
mPasswordView.setText("");
super.onResume();
}
}
跳轉(zhuǎn)過去的second.activity各位就隨便弄一個(gè)吧!不過需要記住的就是新增了activity后記著要在AndroidManifest.xml中添加這個(gè)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="密碼匹配成功則自動(dòng)登錄" />
</LinearLayout>
</merge>
其實(shí)最關(guān)鍵的就是知道edittext的一些監(jiān)聽的函數(shù)了,例如還有一些自動(dòng)補(bǔ)全特別是用于賬號(hào)輸入的時(shí)候,這里主要就是用到了監(jiān)聽edittext的變化用到了addTextChangedListener,并且配合TextWatcher()就能實(shí)現(xiàn)在輸入的過程中進(jìn)行一些操作了,把登錄跳轉(zhuǎn)的方法寫在了onTextChanged里北美托福答案
好了,我這里預(yù)設(shè)的密碼就是123456設(shè)置死了的,大家可以試一試?yán)玻?br />
延伸問題:
1.這款記賬軟件設(shè)置的密碼就是保存在本地的,那么如何保存,讀取這個(gè)設(shè)置的密碼呢?(這個(gè)其實(shí)就設(shè)計(jì)到了本地?cái)?shù)據(jù)的存儲(chǔ),方法也多種多樣,后面有時(shí)間我們接著討論這個(gè)托福改分
希望和大家多多交流,我也是android新兵,希望我們?cè)谶@條路上堅(jiān)持走下去,哪怕是一個(gè)小小的功能,只要能方便用戶,就會(huì)為我們?cè)黾痈嗟氖褂谜吆陀脩?。大家加油,積少成多,集腋成裘雅思答案