android 他们定义对话框
创建一个布局文件 my_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="4dp"
android:text="@string/textView1"
/> <EditText
android:id="@+id/editText_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="4dp"
/> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText_user"
android:layout_below="@+id/editText_user"
android:layout_marginTop="7dp"
android:text="@string/textView2"
/> <EditText
android:id="@+id/editText_pwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_marginTop="4dp"
android:layout_below="@+id/textView2"
/>
</RelativeLayout>
下面是strings.xml文件:
<? xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">demo091801</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string> <string name="MyDialog">自己定义对话框</string>
<string name="textView1">username</string> <string name="textView2">password</string> </resources>
在主activity_main.xml中加入一个button控件,当单击此button时即弹出自己定义的对话框:
<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" > <Button
android:id="@+id/My_Dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/MyDialog"
/>
</RelativeLayout>
图形界面例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHAzMTAwMTg5MzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
在MainActivity.java代码中为button控件设置单击事件监听,并弹出自己定义的对话框:
MainActivity.java:
package com.example.demo091801; import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button btn1 = (Button)findViewById(R.id.My_Dialog); btn1.setOnClickListener(new OnClickListener()
{ @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.my_dialog, null); builder.setTitle("登陆");
builder.setView(view);
builder.setPositiveButton("登陆", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub }
}); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub }
}); AlertDialog dialog = builder.create();
dialog.show(); }
}
); } @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;
} }
作者:http://blog.csdn.net/lp310018931
版权声明:本文博主原创文章,博客,未经同意不得转载。
android 他们定义对话框的更多相关文章
- Android自己定义对话框实现QQ退出界面
效果 首先看下qq的效果图,点击菜单button后点退出就会出现如图的对话框. 从上图能够看出,该对话框有一个圆角,以及标题,提示信息,两个button,button颜色是白色,button点击后背景 ...
- Android课程---关于对话框的学习
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 经常使用的android弹出对话框
我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其它平台开发经验的朋友都会知道,大部分的平台都仅仅提供了几个最简单的实现,假设我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承 ...
- Android 自学之对话框
Android为我们提供了丰富的对话框支持,提供了四种常用的对话框: AlertDialog:功能丰富.实际应用最广泛的对话框. ProgressDialog:进度对话框,该对话框只用于简单的进度条封 ...
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- Android UI系列--对话框(一)(AlertDialog,TimePickerDialog,DatePickerDialog,ProgressDialog)
一.Dialog介绍 dialog就是一个在屏幕上弹出一个可以让用户做出一个选择,或者输入额外的信息的对话框,一个对话框并不会沾满我们整个的屏幕,并且通常用于模型事件当中需要用户做出一个决定后才会继续 ...
- Android自己定义dialog中的EditText无法弹出键盘的解决
近期我独立开发的项目<全医会>已经在内測其中了.非常快将会上架到各大应用市场.之前开发的几个项目都由于一些原因没有上架还是比較遗憾的.所以,近期我心情格外的好. 今天在做一个新项目,专为律 ...
- Android自己定义提示框
在开发中,假设感觉系统自带的提示框不好看,开发人员能够自定义提示框的样式.主要是继承Dialog 程序文件夹结构 关键代码 package com.dzt.custom.dialog; import ...
- Android自己定义矩形及selector、shape的使用
[声明]转载请注明出处.此文出自指尖飞落的博客:http://blog.csdn.net/huntersnail --每天写一篇博客.每天做一点技术积累! Android自己定义矩形及selector ...
随机推荐
- sqlplus登录、连接命令
经常使用: sqlplus username/password 如:普通用户登录 sqlplus scott/tiger sqlplus username/password@net_service ...
- virtenv 0.8.6 发布,虚拟桌面配置工具 - 开源中国社区
virtenv 0.8.6 发布,虚拟桌面配置工具 - 开源中国社区 virtenv 0.8.6 发布,virtenv 是一个用 QT4 开发的应用,用来配置和启动基于 LXC 的虚拟桌面环境.该容器 ...
- hdu3415(单调队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3415 题意:一个长度为n包含正负整数的数环,即第1个的左边是第n个.从中选一个不超过k的序列,使得序列 ...
- 【Energy Big Data】能源互联网和电力大数据
背景 今年的政府工作报告突出了互联网在经济结构转型中的重要地位,报告明白指出:要制定"互联网+"行动计划,推动移动互联网.云计算.大数据.物联网等与现代制造业结合,促进电子商务.工 ...
- Android 网络编程 Socket Http
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- JVM学习03_new对象的内存图讲解,以及引出static方法(转)
目录 -=-讲解对象创建过程中,-=-堆内存和栈内存的情况 -=-构造函数对类对象的成员变量的初始化过程 -=-构造函数出栈 -=-类的方法在不访问类对象的成员变量时造成的内存资源浪费怎么解决? -= ...
- hdu4553(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 线段树功能:update:区间替换 query:询问满足条件的最左断点 分析:poj3667的加 ...
- 使用 SQLNET.EXPIRE_TIME 清除僵死连接
数据库连接的客户端异常断开后,其占有的相应并没有被释放,如从v$session视图中依旧可以看到对应的session处于inactive,且对应的服务器进程也没有释放,导致资源长时间地被占用,对于这种 ...
- Learning Cocos2d-x for WP8(2)——深入刨析Hello World
原文:Learning Cocos2d-x for WP8(2)--深入刨析Hello World cocos2d-x框架 在兄弟篇Learning Cocos2d-x for XNA(1)——小窥c ...
- Mac 登录界面多了一个其它账户删除
原因分析: 在安装一些软件时会自己主动启用root账户,可是在安装完毕后没有关闭root账户,这样就造成系统以为用户要使用root账户,所以在登录界面出现了一个"其它"账户 解决方 ...