PopupWindow的简单使用

测试代码:
package com.zzw.testpopuwindows; import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { LayoutInflater inflater = MainActivity.this.getLayoutInflater();
View view = inflater.inflate(R.layout.item, null); PopupWindow mPopupWindow = new PopupWindow(view, 500, 300); //设置背景的目的是使setOutsideTouchable方法生效
mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));
mPopupWindow.setOutsideTouchable(true);//在外点击消失
// mPopupWindow.showAsDropDown(button);
mPopupWindow.showAtLocation(MainActivity.this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
}
});
} }
item.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:background="@android:color/darker_gray"
android:orientation="vertical" > <ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" /> <TextView
android:layout_gravity="center"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PopupWindow显示"
android:textColor="@android:color/holo_red_light" /> </LinearLayout>
PopupWindow的简单使用的更多相关文章
- PopupWindow的简单使用(结合RecyclerView)
Android弹窗: 在Android中弹出式菜单(以下称弹窗)是使用十分广泛一种菜单呈现的方式,弹窗为用户交互提供了便利.关于弹窗的实现大致有以下两种方式AlertDialog和PopupWindo ...
- Android—PopupWindow的简单使用
PopupWindow 是一个可以显示在当前 Activity 之上的浮动容器,这个Demo要实现的功能是,点击布局中的两个按钮,进而控制PopupWindow的显示与消失,代码中有详细的注释首先看一 ...
- Popupwindow 的简单实用,(显示在控件下方)
第一步: private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML <?xml version="1.0" e ...
- 安卓学习笔记:使用PopupWindow创建简单菜单
PopupWindow是一个弹出式窗口,它可以展示任意View.他会浮在当前窗口的上方展示. 下面看代码: public class MyActivity extends Activity { pri ...
- PopupWindow(2)简单示例-自定义弹出菜单
本示例,用 popupWindow 自定义弹出菜单 public class CustomActionProvider extends ActionProvider implements OnMenu ...
- (转载) popupWindow 指定位置上的显示
popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报 分 ...
- Android PopupWindow使用方法小结
前几天要用到PopupWindow,一时竟想不起来怎么用,赶紧上网查了查,自己写了个demo,并在此记录一下PopupWindow的用法. 使用场景 PopupWindow,顾名思义,就是弹窗,在很多 ...
- 【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等
朝花夕拾----新组件的学习和使用 分类: Android UI2015-06-26 11:31 440人阅读 评论(0) 收藏 举报 uidialogMaterial 目录(?)[-] Mate ...
- Android:PopupWindow简单弹窗改进版
Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...
随机推荐
- iOS 中关闭键盘方法
在 iOS 程序中当想要在文本框中输入数据,轻触文本框会打开键盘.对于 iPad 程序,其键盘有一个按钮可以用来关闭键盘,但是 iPhone 程序中的键盘却没有这样的按钮,不过我们可以采取一些方法关闭 ...
- 避免多层回调,Node.js异步库Async使用(series)
未使用Async之前coffeescript写的代码: exports.product_file_add = (req,res) -> if !req.param('file_id') retu ...
- sqlite支持的数据库类型
http://www.sqlite.org/datatype3.html 默认只支持:NULL,INTEGER,REAL,TEXT,BLOB
- 为什么需要auto_ptr_ref
这几天开始拜读侯捷先生和孟岩先生的译作<C++标准程序库:自修教程与参考手册> .两位先生确实译功上乘,读得很顺.但是读到P55页关于auto_ptr_ref的讨论,却百思不得其解:为什么 ...
- Oracle GoldenGate 11.2 OGG-01168(转)
为客户部署的Oracle GoldenGate在测试阶段出现如下的错误: 2012-04-24 10:45:20 ERROR OGG-01168 Oracle GoldenGate Deliv ...
- 项目积累——CSS应用
<tr onmouseover=" this.style.backgroundColor= '#E0FFFF' " onmouseout="this.style. ...
- vc 递归删除非空文件夹
我觉得这是一个非常不错的递归例子 头文件 #pragma once #include <atlstr.h> #include <io.h> #include <strin ...
- jmeter的分布式部署
在使用Jmeter进行性能测试时,如果并发数比较大(比如5000+并发),单台电脑的配置(CPU和内存)可能无法支持(公司配的联想e450家庭用笔记本一般到1000就会卡死),这时可以使用Jmeter ...
- python学习笔记(Tkinter编程利用Treeview实现表格自动更新)
博主今天总结这段时间抽空写的一个GUI编程项目 功能是查看本地打印机队列,可选择指定队列重新打印 直接上图 UI设计包括3个区域左上方,右上方和下方列表区域 使用网格grid方法来分配位置 下面是界面 ...
- SmartWiki开发日志之环境配置和系统安装
SmartWiki是基于laravel5.2开发的在线文档管理系统. 最低需要PHP5.6+MySql5.7.同时PHP需要开启一下扩展: MCrypt GD PDO PDO_mysql mbstri ...