Android開發(fā)的QQ登錄頁面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.sc.qq_login.MainActivity"
    tools:ignore="MergeRootFrame" 
    android:orientation="vertical"
    
    >
    <ImageView 
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/qq"
        />
    <EditText 
        android:id="@+id/qqNumber" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="請輸入qq號"  
        />
    <EditText 
        android:id="@+id/qqPassword"
        android:inputType="textPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="請輸入qq密碼"
        />

    <CheckBox
        android:id="@+id/checkBoxBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="記住密碼" 
        />
    <Button 
        android:id="@+id/loginBtn"
        android:text="登錄"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
        
</LinearLayout>
package com.sc.qq_login;

import android.R.id;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Build;

public class MainActivity extends Activity implements View.OnClickListener{
    private EditText number;
    private EditText password;
    private Button login_btn;
    private CheckBox checkbox_btn;
    SharedPreferences sharedPreferences;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化常見的控件
        number = (EditText)findViewById(R.id.qqNumber);
        password = (EditText)findViewById(R.id.qqPassword);
        checkbox_btn = (CheckBox)findViewById(R.id.checkBoxBtn);
        login_btn = (Button)findViewById(R.id.loginBtn);
        login_btn.setOnClickListener(this);
        
        //數(shù)據(jù)的保存使用sharedPreference,Android中提供了一個特有的數(shù)據(jù)保存機制
        //userinfo文件將會生成在應用文件夾下-------一個xml格式的文件
        //一般情況下,應用自己的數(shù)據(jù)只有當前應用可以去讀,所以通常會寫
        sharedPreferences = getSharedPreferences("userinfo", 0);
        //讀取數(shù)據(jù)
        String usernameV = sharedPreferences.getString("username", "");
        String passwordV = sharedPreferences.getString("password", "");
        if(usernameV.length()>0&&passwordV.length()>0){
            number.setText(usernameV);
            password.setText(passwordV);
            checkbox_btn.setChecked(true);
        }
        
        
    }
    @Override
    public void onClick(View arg0) {
        int login_id = arg0.getId();
        switch (login_id) {
        case R.id.loginBtn:
        {
            String numberValue = number.getText().toString().trim();
            String passwpordValue = password.getText().toString().trim();
            if(TextUtils.isEmpty(numberValue) && TextUtils.isEmpty(passwpordValue)){
                Toast.makeText(this, "用戶名和密碼不能為空", 0).show();
                return;
            }else{
                Toast.makeText(this, "登錄", 0).show();
            }
            //勾選checkBox的時候措近,將數(shù)據(jù)保存
            boolean checked = checkbox_btn.isChecked();
            if (checked) {
                Toast.makeText(this, "記住密碼登錄", 0).show();
                
                //向sharedPreference寫數(shù)據(jù)
                Editor edit = sharedPreferences.edit();
                edit.putString("username", numberValue);
                edit.putString("password", passwpordValue);
                edit.commit();
            }else{
                Toast.makeText(this, "沒記住密碼登錄", 0).show();
            }
            
        }
            break;

        default:
            break;
        }
        
    }
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末杜窄,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子卦溢,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,036評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件研儒,死亡現(xiàn)場離奇詭異,居然都是意外死亡刊殉,警方通過查閱死者的電腦和手機殉摔,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來记焊,“玉大人逸月,你說我怎么就攤上這事”槟ぃ” “怎么了碗硬?”我有些...
    開封第一講書人閱讀 164,411評論 0 354
  • 文/不壞的土叔 我叫張陵瓤湘,是天一觀的道長。 經(jīng)常有香客問我恩尾,道長弛说,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,622評論 1 293
  • 正文 為了忘掉前任翰意,我火速辦了婚禮木人,結果婚禮上,老公的妹妹穿的比我還像新娘冀偶。我一直安慰自己醒第,他們只是感情好,可當我...
    茶點故事閱讀 67,661評論 6 392
  • 文/花漫 我一把揭開白布稠曼。 她就那樣靜靜地躺著,像睡著了一般客年。 火紅的嫁衣襯著肌膚如雪霞幅。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,521評論 1 304
  • 那天量瓜,我揣著相機與錄音司恳,去河邊找鬼。 笑死榔至,一個胖子當著我的面吹牛抵赢,可吹牛的內容都是我干的。 我是一名探鬼主播唧取,決...
    沈念sama閱讀 40,288評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼铅鲤,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了枫弟?” 一聲冷哼從身側響起邢享,我...
    開封第一講書人閱讀 39,200評論 0 276
  • 序言:老撾萬榮一對情侶失蹤宙暇,失蹤者是張志新(化名)和其女友劉穎胆剧,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體核无,經(jīng)...
    沈念sama閱讀 45,644評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡韩容,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,837評論 3 336
  • 正文 我和宋清朗相戀三年款违,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片群凶。...
    茶點故事閱讀 39,953評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡插爹,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情赠尾,我是刑警寧澤力穗,帶...
    沈念sama閱讀 35,673評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站气嫁,受9級特大地震影響当窗,放射性物質發(fā)生泄漏。R本人自食惡果不足惜寸宵,卻給世界環(huán)境...
    茶點故事閱讀 41,281評論 3 329
  • 文/蒙蒙 一崖面、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧邓馒,春花似錦嘶朱、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽脉课。三九已至救军,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間倘零,已是汗流浹背唱遭。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留呈驶,地道東北人拷泽。 一個月前我還...
    沈念sama閱讀 48,119評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像袖瞻,于是被迫代替她去往敵國和親司致。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,901評論 2 355

推薦閱讀更多精彩內容