PopupWindow
2016-05-29 00:00
471 查看
摘要: PopupWindow 的简单使用
CustomerPopWindow popWindow = new CustomerPopWindow(mContext); popWindow.showPopup(toolbar); //类 public class CustomerPopWindow extends PopupWindow { private static final String TAG = "CustomerPopWindow"; public CustomerPopWindow(final Context context){ LayoutInflater layoutInflater = LayoutInflater.from(context); View popView = layoutInflater.inflate(R.layout.customer_popup, null, false); // 设置SelectPicPopupWindow的View this.setContentView(popView); this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置SelectPicPopupWindow弹出窗体可点击 this.setFocusable(true); this.setOutsideTouchable(true); // 点击“返回Back”也能使其消失,并且并不会影响你的背景 //this.setBackgroundDrawable(new BitmapDrawable(context.getResources(), // Bitmap.createBitmap(1,1,Bitmap.Config.ARGB_8888))); this.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); this.update(); TextView tvAllCustomer = (TextView) popView.findViewById(R.id.tv_all_customer); TextView tvWechatCustomer = (TextView) popView.findViewById(R.id.tv_wechat_customer); TextView tvOtherCustomer = (TextView) popView.findViewById(R.id.tv_other_customer); tvAllCustomer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "==tvAllCustomer=="); CustomerPopWindow.this.dismiss(); } }); tvWechatCustomer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "==tvWechatCustomer=="); CustomerPopWindow.this.dismiss(); } }); tvOtherCustomer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "==tvOtherCustomer=="); CustomerPopWindow.this.dismiss(); } }); } public void showPopup(View parent) { if(!this.isShowing()){ //int[] location = new int[2]; //parent.getLocationOnScreen(location); //this.showAtLocation(parent, Gravity.TOP|Gravity.CENTER_HORIZONTAL, // location[0]-this.getWidth(), location[1]); this.getContentView().measure(0,0); //测量ContentView尺寸 int xPos = (parent.getWidth() - this.getContentView().getMeasuredWidth()) / 2; //获取偏移量 this.showAsDropDown(parent, xPos, 0); }else{ this.dismiss(); } } }
相关文章推荐
- Android应用架构之Retrofit使用
- 运维小白部署网站踩坑全过程
- 【BUG】hadoop fs -mkdir:No such file or directory
- Linux-配置vim开发环境
- 型网站页面静态化解决方案 freemarker
- linux各个文件夹代表的意义(最完整版本)
- 第二章 微服务架构搭建 + 服务启动注册
- iptables(一)详细教程:基础、架构、清空规则、追加规则、应用实例
- Linux下安装gcc,gdb,MySQL以及vim的配置
- 防止linux命令执行中断
- linux目录和文件名的命名规则
- windows系统环境下,让tomcat自动重启的脚本
- jsp和servlet的关系?答:jsp就是servlet,tomcat会把jsp编译成servlet,servlet就是一个java类,在tomcat下的work文件夹中
- shell编程知识点集锦
- shell编程知识点集锦
- nginx笔记
- Property
- Linux写时拷贝技术(copy-on-write)
- linux中的数值运算
- Centos 安装golang beego