《黑马程序员》 安卓登录小案例
来源:互联网 发布:mysql select 临时表 编辑:程序博客网 时间:2024/04/29 17:16
布局文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="200dip" android:orientation="vertical" android:padding="10dip" > <!-- 标题 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录测试" android:textSize="28sp" /> </LinearLayout> <!-- 内容 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3" android:gravity="center" android:text="用户名" android:textSize="18sp" /> <EditText android:id="@+id/l_uname" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:hint="您的用户名..." android:textSize="18sp" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3" android:gravity="center" android:text="密码" android:textSize="18sp" /> <EditText android:id="@+id/l_pwd" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:hint="您的密码..." android:password="true" android:textSize="18sp" /> </LinearLayout> </LinearLayout> <!-- 按钮 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="horizontal" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="e_login" android:text="登录" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="e_exit" android:text="退出" /> </LinearLayout> </LinearLayout></LinearLayout>
布局效果图:
activity及事件代码如下:
import android.app.Activity;import android.os.Bundle;import android.os.Process;import android.text.TextUtils;import android.view.View;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {//定义控件private EditText et_username, et_userpwd;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 初始化控件et_username = (EditText) this.findViewById(R.id.l_uname);et_userpwd = (EditText) this.findViewById(R.id.l_pwd);}//登录功能的事件代码public void e_login(View v) {// 获取用户名和密码String userName = et_username.getText().toString().trim();String userPwd = et_userpwd.getText().toString().trim();if (TextUtils.isEmpty(userName) | TextUtils.isEmpty(userPwd)) {// 如果用户名或密码为空// 有一个为假则为假使用|,有一个为假即为假Toast.makeText(this, "用户名和密码不能为空", 0).show();} else if ("heima".equals(userName) && "88888".equals(userPwd)) {Toast.makeText(this, "登录成功", 0).show();} elseToast.makeText(this, "用户名或密码不对", 0).show();}//退出事件的代码 public void e_exit(View v){//如何自杀了,先获取到进程对象然后使用自杀的方式将其自杀 Process p=new Process();//如何得到当前应用的进程的idp.killProcess(Process.myPid());}}
运行之后的效果图片:
今天是上班的最后一天了。做这个小案例。以示怀念。
0 0
- 《黑马程序员》 安卓登录小案例
- 黑马程序员_一个登录注册小案例
- 黑马程序员_用户登录注册案例
- 黑马程序员之安卓开发小技巧
- 黑马day14 过滤器之自动登录小案例
- 黑马day14 过滤器之自动登录小案例
- 黑马程序员_集合实现控制台登录注册案例
- 黑马程序员_关于使用IO进行登录注册案例
- 安卓-拨打电话的小案例
- 黑马程序员:交通灯案例
- 黑马程序员:交通灯案例
- 黑马程序员—TCP-客户端并发登录小例子
- 黑马程序员 安卓基础day01
- 黑马程序员 安卓基础学习笔记
- android登录界面小案例
- 黑马程序员 C#学习笔记③ ADO.NET实现登录案例
- 黑马程序员--Java编程之用户注册登录案例及MVC初识
- 安卓 popuWindow 弹出一个界面小案例
- 图解FFMPEG打开媒体的函数avformat_open_input
- Dremel: Interactive Analysis of WebScale 地址
- Linux 系统挂载数据盘
- ?super T 和? extends T区别
- “并发用户数”、“系统用户数”和“同时在线用户数”的计算公式
- 《黑马程序员》 安卓登录小案例
- StringUtils 源码,使用的是commons-lang3-3.1包。
- linux(ubuntu 14.04)安装,删除mysql,更改数据库路径(datadir)和帐户密码
- Opencv 里的solvePnP函数使用问题
- 自创建一个带xib的UIView
- 字符串的全排列和组合算法
- SSH+Oracle整个问题9 关于BigDecimal 和Int整数比较大小的问题
- Android-GPS卫星定位-基于网络及GPS
- JavaMail