易Android登录Demo
Android 登录 Demo
2023-09-14 09:08:06 时间
上一页介绍Android项目简单的页面跳转实例,算是对开发环境的熟悉,这一篇将在此基础上增加一些简单的逻辑,实现登录的效果。
登录之前:
登录成功:
登录信息有误:
在主页面上加入两个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,Android系统加密狗的设计与实现
- android开发笔记之 Android代码混淆打包
- android实现免费短信验证
- android sdk安装过程,图文详解Android 3.0 SDK安装教程
- android 定时器重置,Android定时器延迟和重置[通俗易懂]
- android scaleanimation动画,Android 的ScaleAnimation 缩放动画基本运用
- android系统中toast是什么_Android个人资料简单布局
- Android触摸事件_android设置按钮点击事件
- android activitymanager 系统api_Android view
- android 复制控件,Android长按复制文本功能[通俗易懂]
- Android Services Library_android freeware
- Android 数据库加密 android-database-sqlcipher 开源版本编译过程
- 软件分享 | 第三十六期 蓝光线路 点播直播一体TV盒子(Android、Pad、TV、BOX)
- 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | 加固厂商在 ART 下使用的两种类加载器 | InMemoryDexClassLoader 源码 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ⑤ ( 执行 init-android-libyuv.sh | 执行 init-android-soundtouch.sh )
- 【Android UI】Canvas 画布 ③ ( Canvas 图层栈 | Canvas#saveLayer() 新建图层 | Canvas 状态栈保存信息标志位 )
- Android测量View宽和高的一般通用方法详解手机开发
- Android开发中遇到的问题(三)——eclipse创建android项目无法正常预览布局文件详解手机开发
- Android开发中遇到的问题(二)——新建android工程的时候eclipse没有生成MainActivity和layout布局详解手机开发
- [android] 保存文件到手机内存详解手机开发
- Android View底层到底是怎么绘制的详解手机开发
- android 防止反编译的若干方法详解手机开发
- Android Studio 导入项目 出现安装Error:Cause: failed to find target with hash string ‘android-23’ 等错误详解手机开发
- Android访问Linux服务器:探索无线登录的新方式(安卓登录linux)
- 前 Sun 公司 CEO 作证 Android 没有授权问题
- android avd 连接外部服务器的方法
- Android实现PHP连接MySQL进行数据交互(android通过php连接mysql)
- Android基站定位原理及实现代码
- Android利用ViewPager实现滑动广告板实例源码
- android使用uinput模拟输入设备的方法
- Android下保存简单网页到本地(包括简单图片链接转换)实现代码