android--------Popupwindow的使用

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

PopupWindow在Android.widget包下,项目中经常会使用到PopupWindow做菜单选项,  PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activity之上的。

效果图:

MainActivity.java

public class MainActivity extends Activityimplements OnClickListener {private PopupWindow mPopWindow;private View parentView;private Context context;ImageView mImageViewBar;@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);context = this;initView();}private void initView() {// TODOAuto-generated method stubparentView =getLayoutInflater().inflate(R.layout.activity_main,null);mImageViewBar =(ImageView) findViewById(R.id.menu);mImageViewBar.setOnClickListener(this);showPopupWindow();}private void showPopupWindow() {LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View contentView =inflater.inflate(R.layout.popuplayout,null);mPopWindow = newPopupWindow(contentView);mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);mPopWindow = newPopupWindow();// 设置SelectPicPopupWindow的ViewmPopWindow.setContentView(contentView);// 设置SelectPicPopupWindow弹出窗体的宽mPopWindow.setWidth(LayoutParams.WRAP_CONTENT);// 设置SelectPicPopupWindow弹出窗体的高mPopWindow.setHeight(LayoutParams.WRAP_CONTENT);// 设置SelectPicPopupWindow弹出窗体可点击mPopWindow.setFocusable(true);mPopWindow.setOutsideTouchable(true);// 刷新状态mPopWindow.update();// 实例化一个ColorDrawable颜色为半透明ColorDrawable dw = new ColorDrawable(0000000000);// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener,设置其他控件变化等操作mPopWindow.setBackgroundDrawable(dw);contentView.findViewById(R.id.memu1).setOnClickListener(this);contentView.findViewById(R.id.memu2).setOnClickListener(this);contentView.findViewById(R.id.memu3).setOnClickListener(this);}@Overridepublic void onClick(View v) {int id =v.getId();switch (id) {case R.id.menu:mPopWindow.showAsDropDown(mImageViewBar);break;case R.id.memu1: {Toast.makeText(context,"消息", Toast.LENGTH_SHORT).show();mPopWindow.dismiss();}break;case R.id.memu2: {Toast.makeText(context,"收藏", Toast.LENGTH_SHORT).show();mPopWindow.dismiss();}break;case R.id.memu3: {Toast.makeText(context,"首页", Toast.LENGTH_SHORT).show();mPopWindow.dismiss();}break;}}@Overrideprotected void onDestroy() {// TODOAuto-generated method stubsuper.onDestroy();mPopWindow.dismiss();}}

 

 源代码下载

转载于:https://my.oschina.net/zhangqie/blog/793726

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542183.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用JavaScript中的示例的escape()函数

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通过网络传输数据或有时将数据保存到数据库…

安装虚拟机的脚本

1. 先安装生成自动安装脚本的工具 yum install system-config-kickstart -y 2. 打开这个软件 system-config-kickstart 基本设置:更改时区为上海,设置root用户密码 2)设置安装方法为网络安装,将共享的镜像文件地址正确填写 3&…

小小小游戏

写着玩 FlappyBird 视频:https://pan.baidu.com/s/1sljIR5z 游戏:https://pan.baidu.com/s/1ge8j7Ej 项目:https://pan.baidu.com/s/1eSysxpw Breakout 视频:https://pan.baidu.com/s/1gfhv4hd 项目:https://pan.baidu.com/s/1hs8xPly QBert 视频:https://pan.baidu.com/s/1s…

go在方法中修改结构体的值_[Go]结构体及其方法

结构体类型可以包含若干字段,每个字段通常都需要有确切的名字和类型。也可以不包含任何字段,这样并不是没有意义的,因为还可以为这些类型关联上一些方法,这里可以把方法看作事函数的特殊版本。函数事独立的程序实体,可…

to_number用法示例_Number()函数以及JavaScript中的示例

to_number用法示例Number()函数 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Rea…

系统延时任务及定时任务

1. 系统延时任务&#xff1a; at相关命令 at time 设定任务执行时间at> rm -fr /mnt/* 任务动作at> <EOT> <<ctrld 执行任务at的命令&#xff1a; -l ##查看任务列表-c …

cpn tools查看运行时间_Jmeter在Linux下的运行测试

一、JMeterApache JMeter是Apache组织开发的基于Java的压力测试工具。用于对软件做压力测试&#xff0c;它最初被设计用于Web应用测试&#xff0c;但后来扩展到其他测试领域。1.1、JMeter的作用能够对HTTP和FTP服务器进行压力和性能测试&#xff0c; 也可以对任何数据库进行同样…

css div滚动_如何使用CSS创建可垂直滚动的div?

css div滚动Introduction: 介绍&#xff1a; Dealing with divs has become a regularity and divs are used for many purposes like to structure our code and to segregate our various sections of codes. Besides, we are also aware of many properties that we can im…

Linux中磁盘分区的管理

1. 本地存储设备的识别 fdisk -l真实存在的设备cat /proc/partitions系统识别的设备blkid系统可使用的设备df系统正在挂载的设备 真实存在的设备不一定可识别&#xff0c;识别到的的设备不一定可使用 2. 设备的挂载和卸载 1&#xff09;设备名称 /dev/xdx …

python中时间的加减_python日期加减

python中关于时间和日期函数的常用计算总结 python中关于时间和日期函数有time和datatime 1.获取当前时间的两种方法: import datetime,time now = time.strftime("%Y-%m-%d %H:%M:%S") print now now = datetime.datetime.now()... 文章 技术小胖子 2017-11-08 848…

bst 删除节点_在BST中删除大于或等于k的节点

bst 删除节点Problem statement: 问题陈述&#xff1a; Given a BST and a value x, write a function to delete the nodes having values greater than or equal to x. The function will return the modified root. 给定一个BST和一个值x &#xff0c;编写一个函数删除值大…

游戏架构之二(转)

棋牌类游戏常用架构&#xff1a; 我从事过4年的棋牌类游戏开发&#xff0c;使用过的架构大致如上&#xff0c;各模块解释如下。 LoginServer&#xff1a; 登陆服务器&#xff0c;主要负责player 的登陆请求&#xff0c;验证player的合法性&#xff0c;为合法的player分配sessio…

对lvm介绍

1. 什么是LVM LVM是 Logical Volume Manager&#xff08;逻辑卷管理&#xff09;的简写&#xff0c;它是Linux环境下对磁盘分区进行管理的一种机制&#xff0c;用户在无需停机的情况下可以方便地调整各个分区大小。 lvm中的一些常见符号及意义 pv物理卷被lv命令处理过的物理分…

pythonweb自动化测试实例_[转载]python webdriver自动化测试实例

python webdriver自动化测试初步印象以下示例演示启动firefox&#xff0c;浏览google.com,搜索Cheese&#xff0c;等待搜索结果&#xff0c;然后打印出搜索结果页的标题from selenium import webdriverfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.w…

repeated_Ruby中带有示例的Array.repeated_combination()方法

repeatedArray.repeated_combination()方法 (Array.repeated_combination() Method) In this article, we will study about Array.repeated_combination() method. You all must be thinking the method must be doing something which is related to creating combinations o…

ApacheHttpServer修改httpd.conf配置文件

转自&#xff1a;https://blog.csdn.net/dream1120757048/article/details/77427351 1. 安装完 Apache HTTP Server 之后&#xff0c;还需要修改一下配置文件。 Apache 的配置文件路径如下&#xff1a; C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf…

大学物理实验电学基本参数的测量实验报告_大学物理电学实验报告

技校网专门为您推荐的类似问题答案问题1&#xff1a;怎样写大学计算机基础有关制作个人简历的实验报告一、实验名称&#xff1a;个人简历的制作 二、实验目的与要求: 1、熟悉Word 2003的基本操作 2、掌握利用网络搜索获得个人简历所需的资料 3、培养同学们动手能力和自学能力。…

python 线程模块_Python线程模块| main_thread()方法与示例

python 线程模块Python threading.main_thread()方法 (Python threading.main_thread() Method) main_thread() is an inbuilt method of the threading module in Python. It is used to return the main Thread object. It is the thread from which the Python interpreter …

linux中系统修复

1. 引导文件丢失 &#xff08;1&#xff09;引导文件所在路径 /boot/grub2/grub.cfg 需提前知道根目录所在分区和内核版本 uname -r 查询内核版本命令 模拟问题 rm -fr /boot/grub2/grub.cfg 一不小心把这玩意儿给删了&#xff0c;还reboot了 完了以后机子开不了了就这情况 …

dw相对路径怎么改_密云ETL怎么收费

密云ETL怎么收费&#xff0c;派客动力&#xff0c;公司依托自有产品&#xff0c;整合行业资源&#xff0c;构建先进的数据管理解决方案&#xff0c;解决企业和组织的核心数据问题以及被影响的业务挑战。这种工具我都使用过&#xff0c;优点有&#xff1a;图形界面&#xff0c;开…