Android简单的自定义用户登陆对话框
来源:互联网 发布:仙灵觉醒仙羽进阶数据 编辑:程序博客网 时间:2024/05/16 09:55
二、涉及到的基本组件和原理
1、基本组件:AndroidUI、View、TextView、EditText、Button、CheckBox、动画Animation、线程Thread及Handler等。
2、原理:点击button前判断用户输入的用户名和密码是否为空,两个都不为空时执行登陆,启动登陆动画,在新线程中模拟从远程登陆的方法(程序中sleep(2000)假设验证登陆失败),刷新界面组件。
三、我的理解和想法,全在代码中.....
package com.ui;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;import android.widget.ViewSwitcher;import com.common.UIHelper;import com.example.appmainui.R;import com.widget.BaseActivity;/** * @name 自定义用户登陆对话框 * @descripation 填写用户名和密码后,执行登陆,点击注册按钮转注册页面 * @author 樊俊彬 * @date 2014-6-8 * @version 1.0 */public class LoginDialogActivity extends BaseActivity {private EditText loginDialogInputUserName;private EditText loginDialogInputPassword;private Button loginDialogButtonRegist;private CheckBox loginDialogCheckBoxRememberMe;private Button loginDialogButtonLogin;private Button loginDialogButtonCancel;private ViewSwitcher loginDialogViewSwitcher;private View loginDialogView;private AnimationDrawable loginDialogAnimationLoading;private boolean isLoginSuccess = false;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.login_dialog);initUI();}/** * 初始化界面组件 */public void initUI() {// 加载界面组件loginDialogInputUserName = (EditText) findViewById(R.id.loginDialogInputUserName);loginDialogInputPassword = (EditText) findViewById(R.id.loginDialogInputPassword);loginDialogButtonRegist = (Button) findViewById(R.id.loginDialogRegisterButton);loginDialogCheckBoxRememberMe = (CheckBox) findViewById(R.id.loginDialogCheckBoxRememberMe);loginDialogButtonLogin = (Button) findViewById(R.id.loginDialogButtonLogin);loginDialogButtonCancel = (Button) findViewById(R.id.loginDialogButtonCancel);loginDialogViewSwitcher = (ViewSwitcher) findViewById(R.id.loginDialogViewSwitcher);loginDialogView = (View) findViewById(R.id.loginDialogViewLoading);// 点击取消按钮时结束loginDialogButtonCancel.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {LoginDialogActivity.this.finish();}});// 点击登陆时执行登陆loginDialogButtonLogin.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// 用户名和密码不能为空String inputUserName = loginDialogInputUserName.getText().toString();String inputPassword = loginDialogInputPassword.getText().toString();if (!inputUserName.equals("")) {if (!inputPassword.equals("")) {// 执行登陆操作,开启登陆动画loginDialogAnimationLoading = (AnimationDrawable) loginDialogView.getBackground();loginDialogAnimationLoading.start();loginDialogViewSwitcher.showNext();loginSystem(inputUserName, inputPassword);} else {Toast.makeText(LoginDialogActivity.this, "请输入密码",Toast.LENGTH_SHORT).show();}} else {Toast.makeText(LoginDialogActivity.this, "请输入用户名",Toast.LENGTH_SHORT).show();}}});// 点击注册按钮时转注册页面loginDialogButtonRegist.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {UIHelper.showRegistUserInfo(LoginDialogActivity.this);}});}/** * 启动新线程验证用户名和密码,登陆到系统,同步刷新界面 * * @param inputUserName * @param inputPassword */protected void loginSystem(String inputUserName, String inputPassword) {// 刷新界面final Handler handler = new Handler() {public void handleMessage(Message msg) {// 登陆成功if (msg.what == 1) {Toast.makeText(LoginDialogActivity.this, "登陆成功",Toast.LENGTH_SHORT).show();finish();}// 登陆失败if (msg.what == 0) {Toast.makeText(LoginDialogActivity.this, "登陆失败",Toast.LENGTH_SHORT).show();loginDialogViewSwitcher.showPrevious();}}};// 登陆验证线程new Thread() {@Overridepublic void run() {super.run();Message msg = new Message();try {// 验证用户名和密码sleep(2000);isLoginSuccess = false;if (isLoginSuccess) {// 登陆成功msg.what = 1;} else {// 登陆失败msg.what = 0;}} catch (InterruptedException e) {e.printStackTrace();msg.what = -1;msg.obj = e;}handler.sendMessage(msg);}}.start();}}
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/logindialog_space" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:id="@+id/login_scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:paddingLeft="14.0dip" android:paddingRight="14.0dip" android:paddingTop="14.0dip" android:scrollbars="none" > <ViewSwitcher android:id="@+id/loginDialogViewSwitcher" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/login_dialog_background" android:paddingBottom="00.0dip"> <!-- 账号与密码输入 --> <LinearLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_marginTop="60.0dip" android:background="@drawable/login_dialog_input" android:orientation="vertical" > <EditText android:id="@+id/loginDialogInputUserName" android:layout_width="fill_parent" android:layout_height="44.0dip" android:background="#00ffffff" android:ems="10" android:hint="点此输入账号/邮箱" android:maxLength="16" android:maxLines="1" android:paddingLeft="12.0dip" android:textColor="#ff1d1d1d" android:textColorHint="#ff666666" android:textSize="16.0sp" /> <View android:layout_width="fill_parent" android:layout_height="1.0px" android:layout_marginLeft="1.0px" android:layout_marginRight="1.0px" android:background="#ffc0c3c4" /> <EditText android:id="@+id/loginDialogInputPassword" android:layout_width="fill_parent" android:layout_height="43dp" android:background="#00ffffff" android:ems="10" android:gravity="center_vertical" android:hint="点此请输入密码" android:inputType="textPassword" android:maxLength="16" android:maxLines="1" android:paddingLeft="12.0dip" android:textColor="#ff1d1d1d" android:textColorHint="#ff666666" android:textSize="16.0sp" /> </LinearLayout> <RelativeLayout android:id="@+id/layout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/layout1" android:layout_marginBottom="00dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_marginTop="0dip" > <CheckBox android:id="@+id/loginDialogCheckBoxRememberMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/login_dialog_checkbox_selector" android:checked="true" android:text="记住我的信息" android:textColor="@color/black" android:textSize="@dimen/text_size_14" /> <Button android:id="@+id/loginDialogRegisterButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="5dip" android:background="@drawable/login_dialog_register_btn_selector" android:clickable="true" android:text="注册新账号" android:textColor="@color/black" android:textSize="@dimen/text_size_12" /> </RelativeLayout> <RelativeLayout android:id="@+id/layout3" android:layout_width="wrap_content" android:layout_height="50dip" android:layout_below="@+id/layout2" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" > <Button android:id="@+id/loginDialogButtonLogin" android:layout_width="140dip" android:layout_height="40dip" android:layout_alignParentLeft="true" android:background="@drawable/login_dailog_button_selector" android:text="登陆" android:textColor="@color/black" android:textSize="@dimen/text_size_20" /> <Button android:id="@+id/loginDialogButtonCancel" android:layout_width="140dip" android:layout_height="40dip" android:layout_alignParentRight="true" android:background="@drawable/login_dailog_button_selector" android:text="取消" android:textColor="@color/black" android:textSize="@dimen/text_size_20" /> </RelativeLayout> </RelativeLayout> <View android:id="@+id/loginDialogViewLoading" android:layout_width="135.0dip" android:layout_height="135.0dip" android:layout_gravity="center" android:background="@anim/login_loading" /> </ViewSwitcher> </ScrollView></RelativeLayout>
0 0
- Android简单的自定义用户登陆对话框
- Android 用户自定义对话框
- Android自定义登陆窗口-对话框
- android 创建一个简单的自定义对话框
- 简单的用户登陆判断
- 简单的用户登陆判断
- Android简单对话框、输入对话框、单选对话框、复选对话框、列表对话框、自定义对话框、时间对话框
- android之自定义简单不平凡的对话框
- Android登陆用户的实现
- 用户登陆与验证的简单实现
- 用户登陆与验证的简单实现
- 简单的JSP用户登陆页面
- 一个简单的用户登陆系统
- SpringLDAP 简单的用户登陆认证
- SSH2+JQuery 简单的用户校验 登陆
- 简单实用的ASP用户登陆模块
- 简单的用户登陆界面c程序
- Android自定义对话框的大小
- metalink mos介绍
- JS随录-2
- 豌豆荚研发管理经验分享-软件项目管理及绩效考核方法
- 关于java中的读写文件
- 解决vs中编译c++项目时报类似:LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”错误
- Android简单的自定义用户登陆对话框
- 支付安全探讨
- java重载
- 刚学unity3d,跟着仿作了flappy bird,记下一些琐碎的心得!
- 各颜色RGB值
- Java 实体转Map
- Alice与Bob问题
- 鬼火(irrlicht)的复燃
- eclipse打开文件或者目录位置