您的位置:首页 > 其它

可记住用户名和密码的登录界面

2015-07-04 11:42 295 查看


<?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/14-111223154547-50"

    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" />

    <CheckBox

        android:id="@+id/rem_pw"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/etPassword"

        android:layout_below="@+id/etPassword"

        android:text="记住密码" />

    <CheckBox

        android:id="@+id/auto_login"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/rem_pw"

        android:layout_alignBottom="@+id/rem_pw"

        android:layout_marginLeft="16dp"

        android:layout_toRightOf="@+id/rem_pw"

        android:text="自动登录" />

    <Button

        android:id="@+id/btnLogin"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/auto_login"

        android:layout_below="@+id/auto_login"

        android:layout_marginLeft="50dp"

        android:layout_marginTop="20dp"

        android:background="#999966"

        android:text="@string/btnLogin" />

</RelativeLayout>

LoginActivity.java

package com.example.minitwittersimulate;

import android.os.Bundle;

import android.app.Activity;

import android.content.SharedPreferences;

import android.view.Menu;

import android.view.Window;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.EditText;

import android.widget.ImageButton;

public class LoginActivity extends Activity {
private EditText userName, password;  
   private CheckBox rem_pw, auto_login;  
   private Button btn_login;  
   private ImageButton btnQuit;  
   private String userNameValue,passwordValue;  
   private SharedPreferences sp;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}

@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;
}

}

Strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="app_name">MiniTwitterSimulate</string>

    <string name="action_settings">Settings</string>

    <string name="hello_world">Hello world!</string>

    <string name="tvName">用户名</string>

    <string name="tvPassword">密码</string>

    <string name="btnLogin">登录</string>

    <string name="tvRegister">没有帐号? <a href="#" mce_href="#">注册</a></string>  

    <string name="tvText">欢迎登陆本系统。</string>

</resources>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: