测试代码:

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的简单使用的更多相关文章

  1. PopupWindow的简单使用(结合RecyclerView)

    Android弹窗: 在Android中弹出式菜单(以下称弹窗)是使用十分广泛一种菜单呈现的方式,弹窗为用户交互提供了便利.关于弹窗的实现大致有以下两种方式AlertDialog和PopupWindo ...

  2. Android—PopupWindow的简单使用

    PopupWindow 是一个可以显示在当前 Activity 之上的浮动容器,这个Demo要实现的功能是,点击布局中的两个按钮,进而控制PopupWindow的显示与消失,代码中有详细的注释首先看一 ...

  3. Popupwindow 的简单实用,(显示在控件下方)

    第一步: private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML <?xml version="1.0" e ...

  4. 安卓学习笔记:使用PopupWindow创建简单菜单

    PopupWindow是一个弹出式窗口,它可以展示任意View.他会浮在当前窗口的上方展示. 下面看代码: public class MyActivity extends Activity { pri ...

  5. PopupWindow(2)简单示例-自定义弹出菜单

    本示例,用 popupWindow 自定义弹出菜单 public class CustomActionProvider extends ActionProvider implements OnMenu ...

  6. (转载) popupWindow 指定位置上的显示

    popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报  分 ...

  7. Android PopupWindow使用方法小结

    前几天要用到PopupWindow,一时竟想不起来怎么用,赶紧上网查了查,自己写了个demo,并在此记录一下PopupWindow的用法. 使用场景 PopupWindow,顾名思义,就是弹窗,在很多 ...

  8. 【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等

    朝花夕拾----新组件的学习和使用 分类: Android UI2015-06-26 11:31 440人阅读 评论(0) 收藏 举报 uidialogMaterial   目录(?)[-] Mate ...

  9. Android:PopupWindow简单弹窗改进版

    Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...

随机推荐

  1. Spring Data Jpa 规范接口表

      Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname ...

  2. OC基础(22)

    NSMutableString基本概念 NSMutableString常用方法 NSMutableString练习 *:first-child { margin-top: 0 !important; ...

  3. Linux-服务排查

    root用户下,操作以下5步: 1.查网络,保证本机与对方互相通信 ifconfig ipconfig ping 2.查Linux的对应服务是否启动,使服务的status保持running状态 比如s ...

  4. 带你快速了解CODESOFT 2015

    CODESOFT是知名的条码标签设计打印软件,现在又推出了最新版CODESOFT 2015,其新功能.大改进让人为之一振.下面跟随小编的脚步,走进CODESOFT 2015,看一看CODESOFT 2 ...

  5. yii中第三方库

    yii中存在一些路径别名:ext:表示包含了所有第三方扩展的目录  参考:http://www.yiiframework.com/doc/guide/1.1/zh_cn/basics.namespac ...

  6. [前端 2]常用的JQuery和Dom页面取值与赋值

    导读:书到用时方恨少,需要基础知识的时候,才悔恨自己没有总结学习好.前段时间调了好长时间的页面,突然发现自己之前不怎么在意的取值和赋值,真的是自己一个很薄弱的地方,有时候查半天都找不到一个对的,现在用 ...

  7. C++ Namespace 详解

    命名空间的定义格式为:(取自C++标准文档) named-namespace-definition: namespace identifier { namespace-body } unnamed-n ...

  8. pyhton标准库 json

    使用loads方法即可将json字符串转换成python对象,对应关系如下: #JSON Python object dict array list string unicode number (in ...

  9. ios学习开发阶段小结

    总结一下,开发了1个月10天的ios经验. 先晒成绩单:两个实验性质的app,一个wifi管家,一个图片壁纸软件 技术小结: 1.熟悉基本的各种ns语法:#import,#include,@class ...

  10. 【MySQL】DNS与MHA/ZABBIX构建的高可用MySQL

    MySQL实例组与DNS和MHA/ZABBIX架构示意图: DNS搭建:http://www.cnblogs.com/jiangxu67/p/4801230.html MHA分析:http://www ...