Android 之 AlertDialog 用户登录
1: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">
<Button
android:id="@+id/btn_show_login_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>
</RelativeLayout>
2:login.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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserName:"/>
<EditText
android:id="@+id/et_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/><!--输入类型为密码-->
</LinearLayout>
</LinearLayout>
3:MainActivity.java
public class MainActivity extends Activity {
private Button btnShowLoginDialog=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnShowLoginDialog=(Button)findViewById(R.id.btn_show_login_dialog);
btnShowLoginDialog.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
LayoutInflater layoutInf=LayoutInflater.from(MainActivity.this);
View loginView=layoutInf.inflate(R.layout.login, null);
//一定要通过loginView.findViewById()来取得控件
final EditText etUserName=(EditText)loginView.findViewById(R.id.et_user_name);
final EditText etPwd=(EditText)loginView.findViewById(R.id.et_password);
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("用户登录");
//对dialog添加视图
dialog.setView(loginView);
dialog.setPositiveButton("登录", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String text="username:"+etUserName.getText()+"password:"+etPwd.getText();
Toast.makeText(MainActivity.this, text, Toast.LENGTH_LONG).show();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
//创建并显示
dialog.create().show();
}
});
}
}
4:运行结果:

Android 之 AlertDialog 用户登录的更多相关文章
- android loginDemo +WebService用户登录验证
android loginDemo +WebService用户登录验证 本文是基于android4.0下的loginActivity Demo和android下的Webservice实现的.l ...
- Google用户登录界面 Android实现
实验效果: 项目目录: Java代码(放在Src文件下) package com.bn.chap9.login; import java.io.BufferedReader; import java. ...
- android安卓Sqlite数据库实现用户登录注册
看了很多别人写的安卓SQlite数据的操作代码,一点也不通俗易懂,我觉得我写的不错,而且安卓项目也用上了,所以在博客园里保存分享一下!建立一个类 并继承SQLiteOpenHelper public ...
- Android 用户登录
1:服务端代码如下 <?php /** *登录成功就返回 1,否则返回 0 */ $REQUEST_METHOD=$_SERVER['REQUEST_METHOD']; if($REQUEST_ ...
- Android中利用httpclient进行网络通信的方法(以用户登录为例说明)
http://www.android100.org/html/201406/09/22915.html 1.服务器端 服务器端和android没有太大关系,对J2EE比较熟悉的话写起来应该很容易,这里 ...
- Android studio 开发一个用户登录界面
Android studio 开发一个用户登录界面 activity_main.xml <?xml version="1.0" encoding="utf-8&qu ...
- Mosquitto搭建Android推送服务(四)Mosquitto服务器用户登录与权限配置
文章钢要: 1.对服务器进行多用户配置 2.根据不同用户给予不同权限 一.Mosquitto的用户机制 mosquitto中可以添加多个用户,只有使用用户名和密码登陆服务器才允许用户进行订阅与发布操作 ...
- [转]好文章:Android的AlertDialog详解
refer:http://www.2cto.com/kf/201205/131876.html AlertDialog的构造方法全部是Protected的,所以不能直接通过new一个AlertDial ...
- 用户登录流程详解 +volley(StringRequest)
在实习期间由于要求使用volley,所以第一次开始接触volley,从一开始的迷茫陌生,到疯狂的查找各种资料,通过在项目中用到的实际问题,我想做一些总结,所以写了这篇文章.下面我将介绍我理解的用户登录 ...
随机推荐
- 真正菜鸟用教程之WQSG Scrip Export WQSG (脚本导出导入工具,PSP、NDS汉化必备 )
先扫盲WQSG是干什么用的 一些掌机类游戏汉化比方PSP NDS 汉化必备之物 它能够依据字典转换文本 假设你不知道这是啥玩意,快去充电染成茜色的坂道 文本提取(导出)方法 (下文称导出文章) 在导出 ...
- Android Dialog AlertDialog
1.普通的对话框 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...
- [Angular 2] Handling Clicks and Intervals Together with Merge
Observable.merge allows you take two different source streams and use either one of them to make cha ...
- [转] 智能指针(三):unique_ptr使用简介
PS: 1. auto_ptr太不安全,可能多个auto_ptr指向一个对象,出现重复释放的问题 2. unique_ptr解决了这个问题,不允许拷贝构造函数和赋值操作符,但是!它支持移动构造函数,通 ...
- Java基础知识强化83:System类之gc()方法(垃圾回收)以及和finalize()区别
1. System概述: System类包含一些有用的类字段和方法.它不能被实例化. 2. gc()方法:垃圾回收器 public static void gc() 调用gc方法暗示着Ja ...
- MySQL(12):windows下解决mysql忘记密码
mysql有时候忘记密码了怎么办?我给出案例和说明!一下就解决了! Windows下的实际操作如下 : 1. 关闭正在运行的MySQL. 2. 打开DOS窗口,转到mysql\bin目录. 3 ...
- spring03autowire属性
1.创建需要的实体类 public class Student { //学生实体类 private String name; //姓名 private Integer age; //年龄 privat ...
- Java分页类 Page
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; ...
- requestAnimationFrame 兼容处理
(function() { ; var vendors = ['ms', 'moz', 'webkit', 'o']; ; x < vendors.length && !wind ...
- JQuery 代码
http://baike.baidu.com/view/136475.htmhttp://www.cnblogs.com/gleamy_ming/archive/2009/04/29/1446492. ...