MiniTwitterSimulate记住密码
来源:互联网 发布:mp3购买推荐淘宝网 编辑:程序博客网 时间:2024/06/06 07:40
LoginActivity:
package com.example.minitwittersimulate;
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.EditText;
public class LoginActivity extends Activity {
private EditText etUsername,etPassword;
private CheckBox cbRemenber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
etUsername=(EditText) findViewById(R.id.etUsername);
etPassword=(EditText) findViewById(R.id.etPassword);
cbRemenber=(CheckBox) findViewById(R.id.cbRemenber);
SharedPreferences sharedPreferences=getSharedPreferences("data", MODE_PRIVATE);
String name=sharedPreferences.getString("name", "");
String pass=sharedPreferences.getString("pass", "");
etUsername.setText(name);
etPassword.setText(pass);
if(!name.equals("")&&!pass.equals("")){
cbRemenber.setChecked(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void login(View view){
String name=etUsername.getText().toString(),pass=etPassword.getText().toString();
if(name.equals("admin")&& pass.equals("admin")){
if(cbRemenber.isChecked()){
SharedPreferences sharedPreferences=getSharedPreferences("data", MODE_PRIVATE);
Editor editor=sharedPreferences.edit();
editor.putString("name", name);
editor.putString("pass", pass);
editor.commit();
}
}
}
}
activity_main.xml:
<LinearLayout 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"
android:orientation="vertical"
android:background="@drawable/loginbg"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoginActivity" >
<include layout="@layout/login_top"/>
<include layout="@layout/login_bottom"/>"
</LinearLayout>
LoginBottom.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvRegist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="21dp"
android:layout_marginTop="18dp"
android:text="@string/tvRegister"
android:autoLink="all"
android:textColorLink="#FF0066CC" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:src="@drawable/panda" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="28dp"
android:src="@drawable/icon" />
</RelativeLayout>
login_top.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/btnbg_roundcorner"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/tvUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/tvName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvUsername"
android:layout_below="@+id/tvUsername"
android:background="@android:drawable/edit_text"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etUsername"
android:layout_below="@+id/etUsername"
android:text="@string/tvPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvPassword"
android:layout_below="@+id/tvPassword"
android:layout_marginTop="16dp"
android:background="@android:drawable/edit_text"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/etPassword"
android:layout_below="@+id/etPassword"
android:layout_marginTop="20dp"
android:background="#FF72CAE1"
android:onClick="login"
android:text="@string/btnLogin" />
<CheckBox
android:id="@+id/cbRemenber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnLogin"
android:layout_alignLeft="@+id/etPassword"
android:layout_marginLeft="16dp"
android:text="记住密码" />
</RelativeLayout>
- MiniTwitterSimulate记住密码
- MiniTwitterSimulate记住密码
- MiniTwitterSimulate
- MiniTwitterSimulate
- MinitwitterSimulate
- minitwittersimulate
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- char 与 unsigned char的本质区别
- html中锚点的使用
- Deep Learning(深度学习)学习笔记整理系列之(七)
- 学习日记-property的参数解析
- js函数的几种写法
- MiniTwitterSimulate记住密码
- 关于皕杰报表授权出现的几种错误
- 几种常见的排序算法,选择排序,冒泡排序,希尔排序,堆排序,快速排序,归并排序,基数排序的比较
- 安卓电源键
- Android批量图片加载经典系列——Volley框架实现多布局的新闻列表
- 读取jar包中图片文件,并转换为BufferImage
- Java学习——何为JNDI
- 项目常见函数封装,基于Jquery
- iOS-检测监听网络状态(WIFI、2G/3G/4G)