PopupWindow --- 弹出底部窗体
2024-09-05 12:53:07
第一步 : 布局文件
<?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;
}
最新文章
- Redmi Note3 hennessy 刷机过程记录
- js中call、apply、bind的用法
- MySql避免重复插入记录
- easyui中tree使用simpleData的形式加载数据
- Web Service学习小结(概念性回忆)-希望你们会喜欢
- HDU-2087 剪花布条
- linux时钟管理
- struts——拦截器
- 感觉tbceditor很不错,如果作者能坚持下来,非常非常看好啊
- IE6中让png的icon图标也透明的完整代码段
- Android 4.4 沉浸式透明状态栏
- 【XSY2843】「地底蔷薇」 NTT什么的 扩展拉格朗日反演
- Nginx 504 Gateway Time-out分析及解决方法
- 关于navicat远程连接mysql问题
- MySql5.5 SQL优化 慢查询日志存储
- 加密算法(扩展知识:Base64编码)
- linux:用户及文件权限管理
- TypeError: HashUpdate fail
- jiekou
- Ext Form
热门文章
- 分布式文件存储——GlusterFS
- 每天一个Linux命令(29)du命令
- python 3 mysql sql逻辑查询语句执行顺序
- Spring Cloud之搭建动态Zuul网关路由转发
- Spring Cloud之Zuul负载均衡
- EntityFramework 学习 一 Migration from Entity Framework 4.1/4.3 to Entity Framework 5.0/6.0
- 大话设计模式--策略模式 strategy -- C++实现实例
- 【原创】cocos2d-x3.9蓝牙开发之蓝牙开启
- Codeforces 459E Pashmak and Graph:dp + 贪心
- BZOJ 2058 [Usaco2010 Nov]Cow Photographs:逆序对【环上最小逆序对】