PopupWindow --- 弹出底部窗体
第一步 : 布局文件
<?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 --- 弹出底部窗体的更多相关文章
- DevExpress第三方控件使用实例之ASPxPopupControl弹出子窗体
弹出页面控件:ASPxPopupControl, <dxpc:ASPxPopupControl ID="popubCtr" runat="server" ...
- Android popupwindow 弹出的位置问题
在Android开发中,需要用到PopupWindow这个类.在初始化完成,显示之前,都需要获得这个对象的width,height去计算popupWindow弹出的位置. 这个时候会发现取得的widt ...
- 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法
今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...
- MyEclipse弹出提示窗体
MyEclipse弹出提示窗体 1.弹窗例如以下
- WPF 介绍一种在MVVM模式下弹出子窗体的方式
主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...
- WPF的WebBrowser屏蔽弹出脚本错误窗体
WPF自带的WebBrowser在訪问一些有问题的网页时常常跳出非常多提示脚本错误的窗体, 可是WPF没有自带屏蔽这些窗体的方法或属性. 所以网上找来一使用反射的方法来屏蔽弹出脚本错误窗体的方法, 非 ...
- WPF 在MVVM模式下弹出子窗体的方式
主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...
- 自定义PopupWindow弹出框(带有动画)
使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { pub ...
- [Prism框架实用分享]如何在主程序中合理的弹出子窗体
大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...
随机推荐
- Mysql 导入实战
这个几天公司迁移预览版数据库,当前公司使用的是 Mysql 数据库,版本为 5.6.迁移的数据库大小也不算很大,2G 多一点,总体以小表为主,就几张表数据比较大,有业务记录表达到了 150W 的数量级 ...
- 【leetcode刷题笔记】Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- F1 score,micro F1score,macro F1score 的定义
F1 score,micro F1score,macro F1score 的定义 2018年09月28日 19:30:08 wanglei_1996 阅读数 976 本篇博客可能会继续更新 最近在 ...
- virtualbox 相关操作
关闭 vboxmanage controlvm nenew poweroff 打开,后台运行 vboxmanage startvm centos0 --type headless 复制虚拟机镜像VBo ...
- Codeforces 876C Classroom Watch:枚举
题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...
- ajax实现聊天室功能
需求如下: 先死后活. 需求分析,分析思路如图所示: 1.创建数据库 create database chat; create table messages( id int unsigned prim ...
- PLSQL Developer使用技巧整理
Shortcut: =============================================================================== Edit/Und ...
- spring boot: 一般注入说明(五) @Component, application event事件为Bean与Bean之间通信提供了支持
spring的事件,为Bean与Bean之间通信提供了支持,当一个Bean处理完成之后,希望另一个Bean知道后做相应的事情,这时我们就让另外一个Bean监听当前Bean所发送的事件. spring的 ...
- BEC listen and translation exercise 31
听力练习: All societies have ways of encouraging and enforcing what they view as appropriate behaviour w ...
- ubuntu命令行卸载软件
“apt-get”命令,这是用于管理已安装程序的通用命令. 安装:apt-get install name 卸载:apt-get remove name 卸载并清除配置:apt-get --p ...