第一步 : 布局文件

<?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:orientation="horizontal" > <LinearLayout
    android:id="@+id/menu_close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_bg" //背景图片 9
android:gravity="center"
android:orientation="vertical" > <LinearLayout
android:id="@+id/menu_close_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_btn_bg" // 选择器
android:gravity="center"
android:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_close" /> // 关闭的图标
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="退出"
android:textColor="#eee" />
</LinearLayout>
</LinearLayout> </LinearLayout>

第二步 点击 事件 调出 PopupWindow 的方法

    if (!menu_display) {    //如果没有显示
// 获取LayoutInflater实例
inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
// 这里的main布局是在inflate中加入的哦,以前都是直接this.setContentView()的吧?呵呵
// 该方法返回的是一个View的对象,是布局中的根
layout = inflater.inflate(R.layout.main_menu, null);
menuWindow = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); // menuWindow.showAsDropDown(layout); //设置弹出效果
// menuWindow.showAsDropDown(null, 0, layout.getHeight());
menuWindow.showAtLocation(this.findViewById(R.id.mainweixin), // 整个布局的下面
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); // 设置layout在PopupWindow中显示的位置
// 如何获取我们main中的控件呢?也很简单
mClose = (LinearLayout) layout.findViewById(R.id.menu_close);
mCloseBtn = (LinearLayout) layout
.findViewById(R.id.menu_close_btn); // 下面对每一个Layout进行单击事件的注册吧。。。
// 比如单击某个MenuItem的时候,他的背景色改变
// 事先准备好一些背景图片或者颜色
mCloseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Toast.makeText(Main.this, "退出",
// Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.setClass(MainWeixin.this, Exit.class);
startActivity(intent);
menuWindow.dismiss(); // 响应点击事件之后关闭Menu
}
});
menu_display = true;
} else { //显示了
// 如果当前已经为显示状态,则隐藏起来
menuWindow.dismiss();
menu_display = false;
}

PopupWindow --- 弹出底部窗体的更多相关文章

  1. DevExpress第三方控件使用实例之ASPxPopupControl弹出子窗体

    弹出页面控件:ASPxPopupControl, <dxpc:ASPxPopupControl ID="popubCtr" runat="server" ...

  2. Android popupwindow 弹出的位置问题

    在Android开发中,需要用到PopupWindow这个类.在初始化完成,显示之前,都需要获得这个对象的width,height去计算popupWindow弹出的位置. 这个时候会发现取得的widt ...

  3. 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法

    今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...

  4. MyEclipse弹出提示窗体

    MyEclipse弹出提示窗体 1.弹窗例如以下

  5. WPF 介绍一种在MVVM模式下弹出子窗体的方式

    主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...

  6. WPF的WebBrowser屏蔽弹出脚本错误窗体

    WPF自带的WebBrowser在訪问一些有问题的网页时常常跳出非常多提示脚本错误的窗体, 可是WPF没有自带屏蔽这些窗体的方法或属性. 所以网上找来一使用反射的方法来屏蔽弹出脚本错误窗体的方法, 非 ...

  7. WPF 在MVVM模式下弹出子窗体的方式

    主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...

  8. 自定义PopupWindow弹出框(带有动画)

    使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { pub ...

  9. [Prism框架实用分享]如何在主程序中合理的弹出子窗体

    大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...

随机推荐

  1. python基础4 ----字符编码

    python基础---字符编码 一.了解字符编码 1. 文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就打开了启动了一个进程,是在内存中的,所以在编辑器编写的内容 ...

  2. 深入浅出聊聊企业级API网关

    http://architect.dataguru.cn/article-11431-1.html API Gateway(API GW / API 网关),顾名思义,是出现在系统边界上的一个面向 A ...

  3. Data Structure Array: Find the two numbers with odd occurrences in an unsorted array

    http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...

  4. 广义表(C++实现)

    广义表是非线性结构,其定义是递归的. 以下给出几种简单的广义表模型: 由上图我们可以看到,广义表的节点类型无非head.value.sub三种,这里设置枚举类型,利用枚举变量来记录每个节点的类型: e ...

  5. 在ubuntu上为android系统编写Linux驱动程序【转】

    本文转载自:http://blog.csdn.net/luoshengyang/article/details/6568411 在智能手机时代,每个品牌的手机都有自己的个性特点.正是依靠这种与众不同的 ...

  6. Docker 单机网络

    Docker Network相关命令 root@ubuntu:~# docker network --help Usage: docker network COMMAND Manage network ...

  7. STL讲解报告

    三十分钟掌握STL STL概述 STL的一个重要特点是数据结构和算法的分离.尽管这是个简单的概念,但这种分离确实使得STL变得非常通用.例如,由于STL的sort()函数是完全通用的,你可以用它来操作 ...

  8. 图解MFC基本框架(深入消息映射机制)

    首先,先看整体的消息流向图: 上图解释: 起点是消息循环,在winmain函数中(mfc中winmain函数是隐含的调用的,在app全局对象构造完后紧接着调用winmain函数),while循环中不断 ...

  9. thinkphp3.2新部署是错

    下载好thinkphp3.2,使用M或者D方法是,报FILE: tp\ThinkPHP\Library\Think\Db.class.php LINE: 42 可能的错误是,配置文件中没有配置数据库连 ...

  10. JQUERY Uploadify 3.1 C#使用案例

    近来因为要做一个上传功能,而firefox又不能直接使用file这样的标签,所以试着用js来写了一个,结果发现代码太多,验证太复杂,而且效果也不理想. 相对的,jquery提供的这一套uploadif ...