Android 中PopupWindow使用 (转)
参考学习后遇到问题:
要引用:有好几个,可以用错误提示解决;
import android.widget.PopupWindow;
import android.widget.Toast;
Activity调用过程 :
首先定义一个BUTTON变量和mContext
private Button mshowBtn;
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(LoginActivity.this, MicroVideoService.class));
bindXMPPService();
setContentView(R.layout.loginpage);
mContext=this;
initView();
}
//指定事件
mshowBtn= (Button) findViewById(R.id.showbtn);
mshowBtn.setOnClickListener(mshowBtnOnClickListener);
//实现事件并调用
private OnClickListener mshowBtnOnClickListener= new OnClickListener(){
@Override
public void onClick(View v) {
showPopWindow(mContext,v);
}
};
(转自:import android.widget.PopupWindow;)
Android 中PopupWindow使用。
PopupWindow会阻塞对话框,要在外部线程 或者 PopupWindow本身做退出才行。
mypopWindow.xml的Layout设计如下
<?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="fill_parent" android:background="#259" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Here is Pop Window" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancle" /></LinearLayout>在MainActivity的Button按钮单击,然后显示PopupWindow。
private void showPopWindow(Context context, View parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View vPopWindow=inflater.inflate(R.layout.mypopwindow, null, false); //宽300 高300 final PopupWindow popWindow = new PopupWindow(vPopWindow,300,300,true); Button okButton = (Button)vPopWindow.findViewById(R.id.button1); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "You click OK", Toast.LENGTH_SHORT).show(); } }); Button cancleButton = (Button)vPopWindow.findViewById(R.id.button2); cancleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub popWindow.dismiss(); //Close the Pop Window } }); popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0); }
Android 中PopupWindow使用 (转)的更多相关文章
- Android中Popupwindow和Dialog的区别
Android中的对话框有两种:PopupWindow和AlertDialog.它们都可以实现弹窗功能,但是他们之间有一些差别,下面总结了一点. (1)Popupwindow在显示之前一定要设置宽高, ...
- Android中PopupWindow用法
参考资料链接:http://developer.android.com/reference/android/widget/PopupWindow.html 在Android中有很多级别的Window, ...
- Android中PopupWindow中有输入框时无法弹出输入法的解决办法
PopupWindow window=new PopupWindow(view, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); //必须让p ...
- android中使用PopupWindow实现弹出窗口菜单
结合上篇android中使用ViewPager实现图片拖动,我们实现了点击“帮助”按钮的功能,这一篇则是接着上一篇,让我们一起来完成“我的”按钮的功能,这一功能,则是使用PopupWindow来实现弹 ...
- Android中的PopupWindow详解
Android的对话框有两种:PopupWindow和AlertDialog.它们的不同点在于: AlertDialog的位置固定,而PopupWindow的位置可以随意 AlertDialog是 ...
- Android中的自定义控件(一)
自定义控件是根据自己的需要自己来编写控件.安卓自带的控件有时候无法满足你的需求,这种时候,我们只能去自己去实现适合项目的控件.同时,安卓也允许你去继承已经存在的控件或者实现你自己的控件以便优化界面和创 ...
- Android中使用SurfaceView+MediaPlayer+自定义的MediaController实现自定义的视屏播放器
效果图如下: (PS本来是要给大家穿gif动态图的,无奈太大了,没法上传) 功能实现:暂停,播放,快进,快退,全屏,退出全屏,等基本功能 实现的思路: 在主布局中放置一个SurfaceView,在Su ...
- Android 使用PopupWindow实现弹出菜单
在本文当中,我将会与大家分享一个封装了PopupWindow实现弹出菜单的类,并说明它的实现与使用. 因对界面的需求,android原生的弹出菜单已不能满足我们的需求,自定义菜单成了我们的唯一选择,在 ...
- Android中那些有你不知道的事
在安卓开发中,总有那么一些看似简单,实则绊脚的难题,等你去探索,等你去解决,也许你已经遇见了解决了,也许你还没碰上,写下这篇总结,希望能帮助那行即将遇到的朋友,快速解决这些小问题! 一.activit ...
随机推荐
- CAS客户端服务器端配置步骤
来自我的个人网站:http://lkf.22web.org/ cas介绍: CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 ...
- SPRING SECURITY 拦截静态资源
情景: <security:intercept-url pattern="/**" access="USER"/> 当在spring securti ...
- AWS CloudFront CDN直接全站加速折腾记The request could not be satisfied. Bad request
ERROR The request could not be satisfied. Bad request. Generated by cloudfront (CloudFront) Request ...
- CentOS系统Kernel panic - not syncing: Attempted to kill init
结果启动虚拟机出现如下问题: Kernel panic - not syncing: Attempted to kill init 解决方法: 系统启动的时候,按下'e'键进入grub编辑界面 ...
- 【iScroll源码学习02】分解iScroll三个核心事件点
前言 最近两天看到很多的总结性发言,我想想今年好像我的变化挺大的,是不是该晚上来水一发呢?嗯,决定了,晚上来水一发! 上周六,我们简单模拟了下iScroll的实现,周日我们开始了学习iScroll的源 ...
- 手把手系列:实现Nat地址转换
1.实验目的: 掌握内网中的主机C1连接到Internet时,通过NAT实现私有全局地址转换. 2.实验拓扑: 3.实验步骤: 步骤一:给主机C1和C2配置IP地址.子网掩码和网关.如图: C1: ...
- linux集群运维工具:pssh
由于需要安装hadoop集群,有10台机器需要安装,一开始打算用SCP复制,后来觉得不可接受(实际现场可能数倍的机器集群,就是10台也不想干).后来在网上找了,发现了clustershell和pssh ...
- yii create url (一)
1.$this->redirect这里的$this是当前的controller.可能是应用程序的也 可能是模块下的 这里仅将解一下第一个参能是url,当url是一个字符串时,它会自己动跳转 如$ ...
- Android 手机卫士--事件传递&响应规则
问题的提出: 本文地址:http://www.cnblogs.com/wuyudong/p/5911187.html ,转载请注明源地址. 前面的文章实现了点击SettingItemView条目的时候 ...
- 【iOS】使用safari对webview进行调试
[iOS]使用safari对webview进行调试 在web开发的过程中,抓包.调试页面样式.查看请求头是很常用的技巧.其实在iOS开发中,这些技巧也能用(无论是模拟器还是真机),不过我们需要用到ma ...