日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

eclipse实现Android登录功能,eclipse开发安卓登录

發布時間:2025/3/15 Android 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 eclipse实现Android登录功能,eclipse开发安卓登录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

劃線的地方怎么解決啊?有沒有大佬知道如何修改

package com.example.login;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.CompoundButton.OnCheckedChangeListener;

import android.widget.EditText;

import android.widget.Toast;

public class LoginActivity extends Activity {

private EditText userName, password;

private CheckBox rem_pw;

private Button btn_login;

private String userNameValue,passwordValue;

private SharedPreferences sp;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//去除標題

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_login);

//獲得實例對象

sp = this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);

userName = (EditText)findViewById(R.id.et_zh);

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

rem_pw = (CheckBox)findViewById(R.id.cb_psd);

btn_login = (Button)findViewById(R.id.btn_login);

//判斷記住密碼多選框的狀態

if(sp.getBoolean("ISCHECK", false))

{

//設置默認是記錄密碼狀態

rem_pw.setChecked(true);

userName.setText(sp.getString("USER_NAME", ""));

password.setText(sp.getString("PASSWORD", ""));

}

// 登錄監聽事件 現在默認為用戶名為:fang 密碼:123

btn_login.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

userNameValue = userName.getText().toString();

passwordValue = password.getText().toString();

if(userNameValue.equals("fang")&&passwordValue.equals("123")){

//跳轉界面

Bundle bundle = new Bundle();

bundle.putString("name", userNameValue);

bundle.putString("psd", passwordValue);

Intent intent = new Intent(WelcomeActivity.this,WelcomeActivity.class);

intent.putExtras(bundle);

startActivity(intent);

//finish();

//登錄成功和記住密碼框為選中狀態才保存用戶信息

if(rem_pw.isChecked())

{

//記住用戶名、密碼、

Editor editor = sp.edit();

editor.putString("USER_NAME", userNameValue);

editor.putString("PASSWORD",passwordValue);

editor.commit();

}

}else{

Toast.makeText(LoginActivity.this,"用戶名或密碼錯誤,請重新登錄", Toast.LENGTH_LONG).show();

}

}

});

//監聽記住密碼多選框按鈕事件

rem_pw.setOnCheckedChangeListener(new OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

if (rem_pw.isChecked()) {

System.out.println("記住密碼已選中");

sp.edit().putBoolean("ISCHECK", true).commit();

}else {

System.out.println("記住密碼沒有選中");

sp.edit().putBoolean("ISCHECK", false).commit();

}

}

});

}

}

總結

以上是生活随笔為你收集整理的eclipse实现Android登录功能,eclipse开发安卓登录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。