QQ登录
来源:互联网 发布:1314 seo标签伪静态 编辑:程序博客网 时间:2024/04/30 06:28
“QQ登录”程序对应的布局文件(activity_main.xml)如下所示:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.bz0209.qq.MainActivity" android:background="#E6E6E6" android:orientation="vertical" > <ImageView android:id="@+id/iv_head" android:layout_width="70dp" android:layout_height="60dp" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:src="@drawable/cc"/> <LinearLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/iv_head" android:layout_margin="10dp" android:background="#ffffff" android:orientation="vertical"> <RelativeLayout android:id="@+id/rl_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="账号"/> <EditText android:id="@+id/et_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toRightOf="@+id/tv_name" android:background="@null"/> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E6E6E6"/> <RelativeLayout android:id="@+id/rl_userpas" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:id="@+id/tv_psw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="密码"/> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toRightOf="@+id/tv_psw" android:inputType="textPassword" android:background="@null"/> </RelativeLayout> </LinearLayout> <Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/layout" android:layout_centerHorizontal="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="20dp" android:background="#3C8DC4" android:text="登录" android:textColor="#ffffff"/></RelativeLayout>Utils类用于实现QQ号码和密码的存储与获取功能:
package com.example.bz0209.qq;import android.content.Context;import android.content.SharedPreferences;import java.util.HashMap;import java.util.Map;/** * Created by Administrator on 2017/6/9. */public class Utils { public static boolean saveUserInfo(Context context ,String number,String password){ SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE); SharedPreferences.Editor edit=sp.edit(); edit.putString("userName",number); edit.putString("pwd",password); edit.commit(); return true; } public static Map<String,String>getUserInfo(Context context){ SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE); String number=sp.getString("username",null); String password=sp.getString("pwd",null); Map<String,String>userMap=new HashMap<String,String>(); userMap.put("number",number); userMap.put("password",password); return userMap; }}在MainActivity中,实现当用户输入完QQ号码和密码,选择记住密码,单击登录按钮时调用Utils.saveUserInfo()方法保存QQ密码:
package com.example.bz0209.qq;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.TextUtils;import android.util.Log;import android.view.View;import android.widget.EditText;import android.widget.Toast;import java.util.Map;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private EditText etNumber; private EditText etPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initview(); Map<String,String>userInfo=Utils.getUserInfo(this); if (userInfo!=null){ etNumber.setText(userInfo.get("number")); etPassword.setText(userInfo.get("password")); } } private void initview() { etNumber=(EditText)findViewById(R.id.et_number); etPassword=(EditText)findViewById(R.id.et_password); findViewById(R.id.btn_login).setOnClickListener( this); } public void onClick(View v){ //当单击登录按钮时 String number=etNumber.getText().toString().trim(); String password=etPassword.getText().toString(); //检验号码和密码是否正确 if (TextUtils.isEmpty(number)){ Toast.makeText(this,"请输入QQ号码",Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(password)){ Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show(); return; } Toast.makeText(this,"登陆成功",Toast.LENGTH_SHORT).show(); Log.i("MainActivity","记住密码:"+number+","+password); boolean isSaveSuccess=Utils.saveUserInfo(this,number,password); if (isSaveSuccess){ Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this,"保存失败",Toast.LENGTH_SHORT).show(); } }}运行结果图:
阅读全文
0 0
- QQ登录
- QQ登录
- qq登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- QQ登录
- qq登录
- qq登录
- QQ快捷登录(sdk登录)
- QQ游戏登录效果
- QQ登录界面
- 华为手机onActivityResult 不执行
- 不想成为好leader的程序猿不是好攻城狮
- HDU 5934 Bomb [强连通+点基]【图论】
- Python正则表达式式序、常用模块
- Cortex-M3/4的Hard Fault调试方法
- QQ登录
- linux ps命令
- 验证码刷新
- Elasticsearch ulimit
- centos7安装配置zabbix
- 第一篇
- 当移动到li标签上,显示对应的div层,并且只有移动其它li标签才会切换显示隐藏
- 使用_Python_和_Asyncio_编写在线多用人游戏(二)
- Android实现下载图片并保存到SD卡中