<Android考证之实训项目三>用户登录对话框设计

项目截图

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:layout_width="match_parent"
  6     android:layout_height="match_parent"
  7     android:background="?attr/colorButtonNormal"
  8     tools:context=".LoginActivity">
  9
 10     <LinearLayout
 11         android:layout_width="match_parent"
 12         android:layout_height="wrap_content"
 13         android:layout_gravity="center"
 14         android:layout_margin="30dp"
 15         android:background="@android:color/black"
 16         android:orientation="vertical">
 17
 18         <LinearLayout
 19             android:layout_width="match_parent"
 20             android:layout_height="match_parent"
 21             android:orientation="vertical">
 22
 23             <TextView
 24                 android:id="@+id/textView"
 25                 android:layout_width="match_parent"
 26                 android:layout_height="50dp"
 27                 android:background="@android:color/black"
 28                 android:gravity="center_vertical"
 29                 android:padding="10dp"
 30                 android:text="用户登陆"
 31                 android:textColor="@android:color/background_light"
 32                 android:textSize="24sp" />
 33         </LinearLayout>
 34
 35         <LinearLayout
 36             android:layout_width="match_parent"
 37             android:layout_height="match_parent"
 38             android:layout_margin="3dp"
 39             android:orientation="vertical">
 40
 41             <LinearLayout
 42                 android:layout_width="match_parent"
 43                 android:layout_height="match_parent"
 44                 android:background="@android:color/background_light"
 45                 android:orientation="horizontal">
 46
 47                 <TextView
 48                     android:id="@+id/textView2"
 49                     android:layout_width="wrap_content"
 50                     android:layout_height="wrap_content"
 51                     android:layout_weight="1"
 52                     android:text="用户名:"
 53                     android:textSize="24sp" />
 54
 55                 <EditText
 56                     android:id="@+id/username"
 57                     android:layout_width="wrap_content"
 58                     android:layout_height="wrap_content"
 59                     android:layout_weight="1"
 60                     android:ems="10"
 61                     android:hint="请填写登陆账号"
 62                     android:inputType="textPersonName" />
 63             </LinearLayout>
 64
 65             <LinearLayout
 66                 android:layout_width="match_parent"
 67                 android:layout_height="match_parent"
 68                 android:background="@android:color/background_light"
 69                 android:orientation="horizontal">
 70
 71                 <TextView
 72                     android:id="@+id/textView3"
 73                     android:layout_width="wrap_content"
 74                     android:layout_height="wrap_content"
 75                     android:layout_weight="1"
 76                     android:text="密码:  "
 77                     android:textSize="24sp" />
 78
 79                 <EditText
 80                     android:id="@+id/passwrod"
 81                     android:layout_width="wrap_content"
 82                     android:layout_height="wrap_content"
 83                     android:layout_weight="1"
 84                     android:ems="10" />
 85             </LinearLayout>
 86
 87         </LinearLayout>
 88
 89         <LinearLayout
 90             android:layout_width="match_parent"
 91             android:layout_height="match_parent"
 92             android:layout_margin="3dp"
 93             android:background="@android:color/darker_gray"
 94             android:orientation="horizontal">
 95
 96             <Button
 97                 android:id="@+id/login"
 98                 android:layout_width="wrap_content"
 99                 android:layout_height="wrap_content"
100                 android:layout_weight="1"
101                 android:text="登陆" />
102
103             <Button
104                 android:id="@+id/cancel"
105                 android:layout_width="wrap_content"
106                 android:layout_height="wrap_content"
107                 android:layout_weight="1"
108                 android:text="取消" />
109         </LinearLayout>
110     </LinearLayout>
111 </LinearLayout>

activity_login.xml

 1 package com.example.login2;
 2
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.Button;
 8 import android.widget.EditText;
 9
10 public class LoginActivity extends AppCompatActivity {
11
12     private EditText username;
13     private EditText password;
14     private Button login;
15     private Button cancel;
16     @Override
17     protected void onCreate(Bundle savedInstanceState) {
18         super.onCreate(savedInstanceState);
19         setContentView(R.layout.activity_login);
20         username =(EditText)findViewById(R.id.username);
21         password =(EditText)findViewById(R.id.passwrod);
22         login = (Button)findViewById(R.id.login);
23         cancel = (Button)findViewById(R.id.cancel);
24         login.setOnClickListener(new View.OnClickListener() {
25             @Override
26             public void onClick(View v) {
27                 String username1 = username.getText().toString();
28                 String password1 = password.getText().toString();
29                 Intent intent = new Intent(LoginActivity.this, MainActivity.class);
30                 if(username1.equals("admin") && password1.equals("12345"))
31                 {
32
33                     intent.putExtra("isLogin",true);
34                     intent.putExtra("username",username1);
35                 }
36                 else
37                 {
38                     intent.putExtra("isLogin",false);
39                 }
40                 startActivity(intent);
41             }
42         });
43         cancel.setOnClickListener(new View.OnClickListener() {
44             @Override
45             public void onClick(View v) {
46                 finish();
47             }
48         });
49     }
50 }

LoginActivity.java

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context=".MainActivity">
 8
 9     <TextView
10         android:id="@+id/tv"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"
13         android:text="Hello World!"
14         app:layout_constraintBottom_toBottomOf="parent"
15         app:layout_constraintLeft_toLeftOf="parent"
16         app:layout_constraintRight_toRightOf="parent"
17         app:layout_constraintTop_toTopOf="parent" />
18
19 </android.support.constraint.ConstraintLayout>

activity_main.xml

 1 package com.example.login2;
 2
 3 import android.content.Intent;
 4 import android.support.annotation.Nullable;
 5 import android.support.v7.app.AppCompatActivity;
 6 import android.os.Bundle;
 7 import android.view.View;
 8 import android.widget.Button;
 9 import android.widget.EditText;
10 import android.widget.TextView;
11
12 public class MainActivity extends AppCompatActivity {
13
14     private TextView tv;
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19         tv = (TextView)findViewById(R.id.tv);
20         Intent intent = getIntent();
21         boolean isLogin = intent.getBooleanExtra("isLogin",false);
22         if(isLogin){
23             String username = intent.getStringExtra("username");
24             tv.setText(username+",欢迎您登陆到我们系统!");
25         }
26         else
27         {
28             tv.setText("您输入的信息有错,请重新登陆!");
29         }
30     }
31 }

MainActivity.java

原文地址:https://www.cnblogs.com/jdxb/p/10929904.html

时间: 2024-08-03 06:54:23

<Android考证之实训项目三>用户登录对话框设计的相关文章

&lt;Android考证之实训项目四&gt;用户注册对话框设计

项目截图 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://sche

&lt;Android考证之实训项目九&gt; SQLit表中图书信息读取

  1 package com.example.sqlitetest2; 2 3 import android.content.Context; 4 import android.database.Cursor; 5 import android.database.sqlite.SQLiteDatabase; 6 import android.database.sqlite.SQLiteOpenHelper; 7 import android.support.v7.app.AppCompatAc

山西高平地域文化导入美术设计实训项目的实践

地域文化,是指某个地域的人们在特定的范围内,在自然环境的基础上,在长期的生产生活中创造的.人类活动的产物.山西高平是神农炎帝的故里,长平之战的发生地,是一个有着很深文化积淀的新兴城市,行政区域是国土面积的万分之一,却浓缩了中国五千年文化的精髓.本文通过对山西高平丰富的历史文化资源的调查研究,探讨如何将地域文化元素导入中职美术设计专业的实训项目教学过程,论证典型地域文化元素在中职美术设计教育中的独特作用,并以此作为教学实训素材,依托带有典型地域文化特征的企业真实案例,结合教育教学实践,探索中职美术

&lt;实训|第三天&gt;Linux登录界面的修改以及Richard Stallman、自由软件运动

在写博客之前我想说两点: 承认一个错误,昨天写的实训第二天,我把redhat6.7写成了Linux6.7,感谢热心人士的指出! 昨天写的文章名字太长了,今天改善,内容感觉表述不全,希望各位谅解! 官方跟我说的是安装配置类的文章不能放进首页中,今天虽然有一点,但是主体部分还是对GUN.Linux和TCP/IP以及IP的认识. 期待已久的linux运维.oracle"培训班"终于开班了,我从已经开始长期四个半月的linux运维.oracle培训,每天白天我会好好学习,晚上回来我会努力更新教

实训第三天

 项目开发计划书 1引言 自媒体的时代,消息的传播异常迅猛.一条网络评论产生的影响不容忽视.在旅游领域,航空公司.酒店等也十分重视网络舆论的主动引导. 1.1编写目的 本文档的编写是为了满足客户对各大的旅游网络评论的及时分析与预警的需求,以求让用户准确的发现社会的舆论导向. 1.2背景 由于网络评论的时效性强,对于意见类诉求若不及时响应,往往对企业形象造成负面影响.文本情感分析是自然语言处理的一个分支,借助有监督学习或无监督学习等方法,让机器理解文本的情感倾向.有了情感分析这一工具,对网络评论的

家乡の战队实训项目博客二

家乡の战队:黄金点项目博客二 1.团队风采 组长:唐宇      16012020 队员:王松鹤  16012016 刘计     16012024 庞啸天 16012011 2.码云地址 https://gitee.com/wcnma/home_troops/tree/master 3. 团队分工 唐宇:团队组长,灵魂核心,领导组员完成java任务,是组员的导向标 评分:9 王松鹤:团队技术担当,高端技术人才,完成主要的java项目 评分:10 刘计:掌握了java的基础知识,擅长与客户交谈,

HTML+CSS网站实训项目总结

  学完HTML+CSS,迎来的最重要的是网站实训和答辩的准备.          第一次的项目分配,因剪刀石头布的手气,得到第二名的机会,却实在不怎么了解各个网站,(当然除了最熟悉的淘宝),选择了组员的要求——国美在线.          国美在线,是国美电器唯一官方商城,中国领先的专业家电网购平台.          这是第一次做的团队小项目,也是第一次以组长的身份和组员进行磨合和合作.          于组长的身份,这是最大的感受除了开始拿到项目的时候的小小激动,就是怕分工不恰当和组织不

【中软实习】之实习实训项目日志

应学校的要求,我们利用暑假及9月份在中软完成为期2个月的实习实训,特将每天的项目情况记录如下,用以备忘之需. [Day0728]:用Java完成一个猜拳小游戏 [Day0729]:用Swing技术完成一个登录模块

struts2 学习(三) ----- 用户登录验证

下面是struts2 的第三个程序(用户登录验证)步骤:(需要新建login.jsp,Login.java和message.jsp) 1.增加Struts框架,步骤在第一篇中. 2.新建一个login.jsp.布局如下: 3.然后新建一个class,名为Login.java,代码如下: 4.在struts.xml文件中,代码如下: 5.新建message.jsp页面,代码如下: 6.OK,运行. **************************************************