- 浏览: 1365142 次
- 性别:
- 来自: 陕西.西安
文章分类
最新评论
-
dare_:
经过试验 设置之后反而更慢没有调用ensureCapacity ...
ensureCapacity()方法提高ArrayList的初始化速度 -
wangchao9053:
[flash=200,200][url][img][list] ...
Only the original thread that created a view hierarchy can touch its views的相关 -
cyb504:
考虑将rb文件代码隐藏:我先使用命令jrubyc将所有rb文件 ...
Ruby学习十 JRuby中调用java代码 -
4562xse3460:
大哥,您这个写反了,差点误导我,我觉得看着就不对。百度第一条就 ...
portrait表示纵向,landscape表示横向 -
yin138:
portrait是肖像画,即竖屏,landscape是风景画, ...
portrait表示纵向,landscape表示横向
http://blog.csdn.net/hellogv/archive/2010/10/21/5956358.aspx
本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处!
介绍过AlertDialog之后,接下来就介绍一下PopupWindow这种对话框。PopupWindow是阻塞对话框,只有在外部线程 或者 PopupWindow本身做退出操作才行。PopupWindow完全依赖Layout做外观,在常见的开发中,PopupWindow应该会与 AlertDialog常混用。
贴出本例中运行的结果图:
main.xml的源码如下:
下图是PopupWindow弹出的截图,这里的PopupWindow是个登录框,点“确定”则自动填写,点“取消”则关闭PopupWindow。
popupwindow.xml的源码:
- <? xml version = "1.0" encoding = "utf-8" ?>
- < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
- android:layout_width = "fill_parent" android:layout_height = "wrap_content"
- android:orientation = "vertical" android:background = "#000000" >
- < TextView android:id = "@+id/username_view"
- android:layout_height = "wrap_content"
- android:layout_marginLeft = "20dip"
- android:layout_marginRight = "20dip" android:text = "用户名"
- android:textAppearance = "?android:attr/textAppearanceMedium" android:layout_width = "fill_parent" />
- < EditText android:id = "@+id/username_edit"
- android:layout_height = "wrap_content"
- android:layout_width = "fill_parent" android:layout_marginLeft = "20dip"
- android:layout_marginRight = "20dip" android:capitalize = "none"
- android:textAppearance = "?android:attr/textAppearanceMedium" />
- < TextView android:id = "@+id/password_view"
- android:layout_height = "wrap_content"
- android:layout_marginLeft = "20dip"
- android:layout_marginRight = "20dip" android:text = "密码"
- android:textAppearance = "?android:attr/textAppearanceMedium" android:layout_width = "fill_parent" />
- < EditText android:id = "@+id/password_edit"
- android:layout_height = "wrap_content"
- android:layout_width = "fill_parent" android:layout_marginLeft = "20dip"
- android:layout_marginRight = "20dip" android:capitalize = "none"
- android:password = "true"
- android:textAppearance = "?android:attr/textAppearanceMedium" />
- < LinearLayout android:id = "@+id/LinearLayout01" android:layout_height = "wrap_content" android:layout_width = "fill_parent" android:gravity = "center" > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:id = "@+id/BtnOK" android:layout_weight = "100" android:text = "确定" > </ Button > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_weight = "100" android:text = "取消" android:id = "@+id/BtnCancel" > </ Button > </ LinearLayout >
- </ LinearLayout >
接下来是程序源码:
- package com.testAlertDialog;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.text.Editable;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.PopupWindow;
- public class testAlertDialog extends Activity {
- Button btnPopupWindow;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super .onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //定义按钮
- btnPopupWindow=(Button)this .findViewById(R.id.Button01);
- btnPopupWindow.setOnClickListener(new ClickEvent());
- }
- //统一处理按键事件
- class ClickEvent implements OnClickListener{
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if (v==btnPopupWindow)
- {
- showPopupWindow(testAlertDialog.this ,
- testAlertDialog.this .findViewById(R.id.Button01));
- }
- }
- }
- public void showPopupWindow(Context context,View parent){
- LayoutInflater inflater = (LayoutInflater)
- context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- final View vPopupWindow=inflater.inflate(R.layout.popupwindow, null , false );
- final PopupWindow pw= new PopupWindow(vPopupWindow, 300 , 300 , true );
- //OK按钮及其处理事件
- Button btnOK=(Button)vPopupWindow.findViewById(R.id.BtnOK);
- btnOK.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- //设置文本框内容
- EditText edtUsername=(EditText)vPopupWindow.findViewById(R.id.username_edit);
- edtUsername.setText("username" );
- EditText edtPassword=(EditText)vPopupWindow.findViewById(R.id.password_edit);
- edtPassword.setText("password" );
- }
- });
- //Cancel按钮及其处理事件
- Button btnCancel=(Button)vPopupWindow.findViewById(R.id.BtnCancel);
- btnCancel.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- pw.dismiss();//关闭
- }
- });
- //显示popupWindow对话框
- pw.showAtLocation(parent, Gravity.CENTER, 0 , 0 );
- }
-
}
发表评论
-
Android检查是否已经连接到网络
2012-05-14 15:40 1141http://blog.csdn.net/kerenigma/ ... -
Android Framework系列之IMF(二)
2011-06-02 10:09 2146InputConnection是IMF里面一个重要的接口,他是 ... -
Android Frameworks系列之IMF(一)
2011-06-02 10:03 1842http://www.pin5i.com/showtopic- ... -
Android线程优先级设置方法
2011-05-28 14:15 3491http://blog.sina.com.cn/s/blog_ ... -
如何连接android数据库
2011-05-27 15:18 2201http://zhidao.baidu.com/questio ... -
ensureCapacity()方法提高ArrayList的初始化速度
2011-05-27 14:33 11497http://www.gznc.edu.cn/yxsz/jjg ... -
java的isAlive 和 join
2011-05-27 13:38 1556join()用于停止当前线程而运行别的线程。 isAli ... -
Linux系统下.ko文件是什么文件?.so文件是什么文件?
2011-05-25 18:55 5396.so 文件是动态链接库文件,相当于 win下的 .dll ... -
使用Geocoder
2011-05-11 10:46 61227.6 使用Geocoder 地理编 ... -
Gallery学习总结--Cache缓存及数据处理流程
2011-05-09 14:21 2153http://hi.baidu.com/%D6%C7%B4%E ... -
关注的网站
2011-04-06 14:37 990http://blog.sina.com.cn/s/blog_ ... -
gallery3d源码学习总结(二)
2011-04-01 10:40 3489http://www.j2megame.com/htm ... -
gallery3d源码学习总结(一)——绘制流程drawFocusItems
2011-04-01 10:14 4825eoe·Android开发者门户 标题: gallery3d ... -
Android 启动过程详解(学习1)
2011-03-31 09:27 2195Android 启动过程详解 http://blog.csd ... -
Android中的WatchDog (2)
2011-03-31 09:11 1038http://wenku.baidu.com/view/09c ... -
Android平台WindowManager运用
2011-03-30 10:00 1787Android平台WindowManager运用 我们A ... -
JPEG Rotation and EXIF Orientation
2011-03-17 14:26 3885http://blog.csdn.net/daisyhd/ar ... -
Android 的动作、广播、类别等标识大全
2011-03-11 10:19 1265Android 的动作、广播、类别等标识大全 Stri ... -
浅析Android MediaProvider之二
2011-03-08 08:27 2625http://www.poemcode.net/2010/01 ... -
Task和Activity相关
2011-02-28 09:21 1519Task和Activity相关 这段时间在做一个项目,发 ...
相关推荐
Android入门第十篇之PopupWindow.docx
介绍过AlertDialog之后,接下来就介绍一下PopupWindow这种对话框。PopupWindow是阻塞对话框,只有在外部线程或者PopupWindow本身做退出操作才行。PopupWindow完全依赖Layout做外观,在常见的开发中,PopupWindow应该...
Android从屏幕底部滑动弹出PopupWindow,有动画效果,类似于sharesdk的分享页面滑动弹出效果。
Android开发之PopupWindow实现弹窗
Android弹窗实现之Popupwindow及DialogFragment。创建并实现PopupWindow布局 实现PopupWindow对象实例 设置PopupWindow背景、动画属性、控件实现及事件监听 显示PopupWindow及位置设定。
android 封装一个通用PopupWindow,避免重复造轮子,简化代码,方便管理。
安卓Android源码——Android之用PopupWindow实现弹出菜单.zip
Android项目实现半透明的popupwindow.rar
android popupwindow 底部灰色背景
Android PopupWindow与Activity之间的数据传递
Android TV 开发有关PopupWindow的KeyListener
PopupWindow的简单使用!
安卓Android源码——精典源码之多级PopupWindow的小demo.zip
AS写的PopupWindow demo blog:http://blog.csdn.net/shenyuanqing/article/details/48136639
Android 单击listview弹出popupwindow弹出框,里面还附带listview右滑删除按钮。博客网址:http://blog.csdn.net/qq_16064871
Android自定义下拉框,用PopupWindow实现
大家可自行学习,研究,并补充该demo.
具体使用请关注博客:http://blog.csdn.net/stoppig 查看《Android中popWindow弹出菜单的编写》这篇文章
Android之用PopupWindow实现弹出listview形式菜单.rar
Android PopupWindow实例 Android PopupWindowAndroid PopupWindowAndroid PopupWindow