上一页介绍Android项目简单的页面跳转实例,算是对开发环境的熟悉,这一篇将在此基础上增加一些简单的逻辑,实现登录的效果。

登录之前:

登录成功:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwODgyNg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" style="width:191px; height:327px">

登录信息有误:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwODgyNg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="width:202px; height:247px">

在主页面上加入两个editText控件,作为用户信息录入的控件。须要做的就是获得这里个editText中的文本。之后对其做一个推断就可以实现登录功能!

相对于之前的页面跳转。仅仅是多加了一个信息验证的推断。体如今代码中就是MainActivity Java类中多了对于用户信息的推断、activity_main
XML文件里多了两个editText控件的代码以及second_main XML文件里对登录成功之后的页面做了一些设计。

MainActivity java代码:

package com.example;

import android.R.color;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.pdf.PdfDocument;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; public class MainActivity extends Activity {
//定义自己的
private Button btnButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnButton = (Button)findViewById(R.id.button1);
btnButton.setWidth(200);
btnButton.setHeight(50);
btnButton.setBackgroundColor(Color.RED); btnButton.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
//获取editText中的文本
EditText userNameEditText=(EditText)findViewById(R.id.editText2);
EditText userPWD=(EditText)findViewById(R.id.editText1); // TODO Auto-generated method stub
//推断登录身份
if (userNameEditText.getText().toString().equals("zhanghui") && userPWD.getText().toString().equals("1")) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
} else {
setTitle("error");
} }
}); } @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;
} }

activity_main XML代码:

<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"
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=".MainActivity" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <!-- editText of userName -->
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="64dp"
android:ems="10"
android:inputType="textPersonName"
android:text="@string/UserName"/> <!-- editText of password -->
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="54dp"
android:ems="10"
android:inputType="numberPassword"
android:text="@string/PWD"> <requestFocus />
</EditText> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:text="@string/login" /> </RelativeLayout>

second_main XML代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:layout_marginLeft="90dp"
android:layout_marginTop="200dp"
android:textColor="#9900CC"
android:textSize="36dp"
/>
</LinearLayout>

这样便能够实现登录中对信息的验证功能了。须要说明的是此登录Demo是在上一篇android页面跳转的Demo基础之上做的,鉴于自己文笔有限。假设有什么看不明确的,大家能够先从上一文章开始。那么这将是简单的事非常多!

版权声明:本文博主原创文章,博客,未经同意不得转载。

易Android登录Demo的更多相关文章

  1. Xamarin.Android再体验之简单的登录Demo

    一.前言 在空闲之余,学学新东西 二.服务端的代码编写与部署 这里采取的方式是MVC+EF返回Json数据,(本来是想用Nancy来实现的,想想电脑太卡就不开多个虚拟机了,用用IIS部署也好) 主要是 ...

  2. 百度地图SDK for Android【Demo兴趣点搜索】

            百度地图SDK为开发人员提供了便捷的检索服务. 今天我将为大家介绍Poi检索相关的内容. 首先,我们要构建一个最主要的地图应用.详细介绍请參考:百度地图SDK for Android[ ...

  3. 如何成功实施SDL提供的官方Android平台Demo

    如何成功实施SDL提供的官方Android平台Demo 作者:雨水  日期:2014-4-30 编写说明:SDL的官方提供了一个Anroid的demo模板SDLActivity,无法直接执行,依照官方 ...

  4. webrtc学习笔记2(Android端demo代码结构)

    最近正在修改webrtc的Android端demo和服务器交互的内容,介绍一下demo的大体结构吧,以便能快速回忆. 环境:Android5.0以上.libjingle_peerconnection_ ...

  5. Android所有Demo资源汇总,太全了(申明:来源于网络)

    Android所有Demo资源汇总,太全了(申明:来源于网络) 地址:http://bbs.csdn.net/topics/391928947

  6. android 官方demo地址

    android官方demo地址都放在了github上:https://github.com/googlesamples

  7. 也谈SSO,一个简单实用的单点登录Demo

    关于SSO(单点登录),百度百科解释如下 : “SSO英文全称Single Sign On,单点登录.SSO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统.它包括可以将这次主要 ...

  8. android登录界面

    在网上在到一个登录界面感觉挺不错的,给大家分享一下~先看效果图: 这个Demo除了按钮.小猫和Logo是图片素材之外,其余的UI都是通过代码实现的. 一.背景 背景蓝色渐变,是通过一个xml文件来设置 ...

  9. 跟服务器交互的登录Demo

    服务器写死 账号密码,演示登录 服务器代码: 开发工具MyEclipse public class LoginServlet extends HttpServlet { /** * The doGet ...

随机推荐

  1. ICTCLAS用的字Lucene4.9捆绑

    它一直喜欢的搜索方向,虽然无法做到.但仍保持了狂热的份额.记得那个夏天.这间实验室.这一群人,一切都随风而逝.踏上新征程.我以前没有自己.面对七三分技术的商业环境,我选择了沉淀.社会是一个大机器,我们 ...

  2. 【SICP读书笔记(二)】使用过程来黏合数据 —— 酷炫吊的消息传递机制

    首先,让我们来看几个内建函数 (cons x y),作用是把x和y绑定成一个序对 (car z),作用是提取z序对的第一个元素 (cdr z),作用是提取z序对的第二个元素 容易看出,这个东西有点类似 ...

  3. Oracle使用并行建索引须要注意的问题

    建索引时.我们为了建索引快.会加上并行,加上并行之后.此列索引就会是并行了. 訪问有并行度的索引时,CBO可能可能会考虑并行运行.这可能会引发一些问题,如在server资源紧张的时候用并行会引起更加严 ...

  4. ios 多线程开发(三)Run Loops

    Run loops是线程相关的一些基本东西.一个run loop是一个处理消息的循环.用来处理计划任务或者收到的事件.run loop的作用是在有事做的时候保持线程繁忙,没事的时候让线程挂起. Run ...

  5. 分布式服务框架 dubbo/dubbox 入门示例(转)

    dubbo是一个分布式的服务架构,可直接用于生产环境作为SOA服务框架. 官网首页:http://dubbo.io/ ,官方用户指南 http://dubbo.io/User+Guide-zh.htm ...

  6. 最少拦截系统(杭电1257)(DP)+(贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. ORACLE 实验一

    实验一:数据定义 实验学时:4学时 实验类型:综合型 实验要求:必修 一.实验目的 1.熟悉Oracle的client配置: 2.掌握SQL Plus的使用: 3.掌握SQL模式定义语句,定义相关的表 ...

  8. maven的webapp产品热销部署eclipse,biz和其他子项目jar一揽子的解决方案无法找到!

    eclipse maven 这也太坑.. ..右键单击该项目 在这里,当地仓库子项目jar新增可以成功启动tomcat... ( maven项目年初进口eclipse他们是正常的. 当...的时候we ...

  9. MongoDB(三)——CRUD

    MongoDB作为非关系型数据库.还是传统数据库的增删改查有很大的差别的.这里仅仅是将知识点进行了一下提纲挈领,实际用的时候.我们百度一下具体使用方法就可以. 先看大的几个方面: 一.对于里边的插入和 ...

  10. 按某个字段来分组、编号的row_number()函数

    本文参考 http://zhidao.baidu.com/link?url=8su4F16Et8Q0S3FmybwniJSI51Ms0AeVujcEXhyEaZh3u5LlOng5Xri_9zHsl7 ...