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 ...
随机推荐
- (medium)LeetCode 222.Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- (easy)LeetCode 235.Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...
- Ibatis 异常:Unable to open connection to "oledb , provider V2.0.0.0 in framework .NET V2.0".
在实际项目中使用了ibatis,然后在开发过程中遇到一些问题,最严重的就是这个“Unable to open connection to "Microsoft SQL Server, pro ...
- xdg-open 打开“irc:*”链接
用于打开chrome浏览器中的"irc://*" #cp /usr/share/applications/xchat.desktop /home/zsj/.local/share/ ...
- 基于RBAC模型的通用企业权限管理系统
1. 为什么我们需要基于RBAC模型的通用企业权限管理系统 管理信息系统是一个复杂的人机交互系统,其中每个具体环节都可能受到安全威胁.构建强健的权限管理系统,保证管理信息系统的安全性是十分重要的.权限 ...
- QTEmbedded VCN实现
1 在QT在第三方插件里加入VNC 进入\src\plugins\gfxdrivers\vnc,qmake -------make--------- make install 把目标文件夹gfxdri ...
- github添加ssh认证
总概:在使用git的时候,和目标仓库建立关系有两种方式https,ssh.一般用的是https认证(这样简单方便),但有个缺点,pull,push等操作需要频繁输入用户验证.虽然可以把用户验证账号密码 ...
- java语言实现的短信接入实例,各公司大同小异
和几家短信平台接触过,都进行了接入测试.总体来说短信发送又快,覆盖率又全的,价格相对贵些.简易选两家分开使用,短信验证码的用一家贵的快的,普通的推广群发短信就用一个便宜的. 下面显示下测试代码 pub ...
- 转——Android应用开发性能优化完全分析
[工匠若水 http://blog.csdn.net/yanbober 转载请注明出处.] 1 背景 其实有点不想写这篇文章的,但是又想写,有些矛盾.不想写的原因是随便上网一搜一堆关于性能的建议,感觉 ...
- Linux input子系统学习总结(二)----Input事件驱动
Input 事件驱动: (主要文件 :drivers/input/evdev.c . drivers/input/input.h)基于kernel 4.0 一. 关键函数调用顺序: 1.inp ...