popwindow创建以及事件拦截与内部包含checkbox选中

2024-02-24 18:40

本文主要是介绍popwindow创建以及事件拦截与内部包含checkbox选中,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1:需求一个这样的弹窗覆盖
这里写图片描述
2:界面搭建以及popuwidow弹出动画效果

   private void cate_screen_poppu() {View view = LayoutInflater.from(this).inflate(R.layout.cate_screen_popup, null);final CheckBox checkbox_all = (CheckBox) view.findViewById(R.id.checkbox_all);final   CheckBox checkbox_serial = (CheckBox) view.findViewById(R.id.checkbox_serial);final  CheckBox checkbox_free = (CheckBox) view.findViewById(R.id.checkbox_free);final CheckBox checkbox_vip = (CheckBox) view.findViewById(R.id.checkbox_vip);final RelativeLayout rl_checkbox_serial = (RelativeLayout) view.findViewById(R.id.rl_checkbox_serial);final RelativeLayout rl_checkbox_all = (RelativeLayout) view.findViewById(R.id.rl_checkbox_all);final RelativeLayout rl_checkbox_free = (RelativeLayout) view.findViewById(R.id.rl_checkbox_free);final RelativeLayout rl_checkbox_vip = (RelativeLayout) view.findViewById(R.id.rl_checkbox_vip);boolean all = PrefUtils.getBoolean(UiUtils.getContext(), "checkbox_all", true);if(all){checkbox_all.setChecked(true);}else{checkbox_all.setChecked(false);}boolean serial = PrefUtils.getBoolean(UiUtils.getContext(), "checkbox_serial", true);if(serial){checkbox_serial.setChecked(true);}else{checkbox_serial.setChecked(false);}boolean free = PrefUtils.getBoolean(UiUtils.getContext(), "checkbox_free", true);if(free){checkbox_free.setChecked(true);}else{checkbox_free.setChecked(false);}boolean vip = PrefUtils.getBoolean(UiUtils.getContext(), "checkbox_vip", true);if(vip){checkbox_vip.setChecked(true);}else{checkbox_vip.setChecked(false);}Button ok_button = (Button) view.findViewById(R.id.ok_button);Button resetting_button = (Button) view.findViewById(R.id.resetting_button);WindowManager manger = (WindowManager) getSystemService(CatagaryActivity.WINDOW_SERVICE);@SuppressWarnings("deprecation")int width = manger.getDefaultDisplay().getWidth()/4;int heigh = manger.getDefaultDisplay().getHeight();mWindow = new PopupWindow(view,3*width, heigh-getStatusBarHeight(this));mWindow.setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));mWindow.setOutsideTouchable(true);mWindow.setTouchable(true);mWindow.setFocusable(true);mWindow.update();View parent = LayoutInflater.from(this).inflate(R.layout.catagary_activity, null);//为popWindow添加动画效果mWindow.setAnimationStyle(R.style.popWindow_animation);// 点击弹出泡泡窗口mWindow.showAtLocation(parent, Gravity.RIGHT, 0,getStatusBarHeight(this));//popupWindow在弹窗的时候背景半透明final WindowManager.LayoutParams params = getWindow().getAttributes();params.alpha = 0.5f;getWindow().setAttributes(params);mWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {@Overridepublic void onDismiss() {params.alpha = 1.0f;getWindow().setAttributes(params);}});//判断是否选中切换书籍筛选状态resetting_button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {checkbox_all.setChecked(true);checkbox_serial.setChecked(true);checkbox_free.setChecked(true);checkbox_vip.setChecked(true);}});ok_button.setOnClickListener(new View.OnClickListener() {public void onClick(View view) {boolean checkbox_allSelected = checkbox_all.isChecked();Log.e("glk",checkbox_allSelected+"");boolean checkbox_serialSelected = checkbox_serial.isChecked();boolean checkbox_freeSelected = checkbox_free.isChecked();boolean checkbox_vipSelected = checkbox_vip.isChecked();if(checkbox_allSelected&&checkbox_serialSelected&&checkbox_freeSelected&&checkbox_vipSelected){radio_cate_screen_book.setTextColor(Color.BLACK);}else{radio_cate_screen_book.setTextColor(Color.RED);}if((checkbox_allSelected&&checkbox_serialSelected&&checkbox_freeSelected&&checkbox_vipSelected)||(!checkbox_allSelected&&!checkbox_serialSelected&&!checkbox_freeSelected&&!checkbox_vipSelected)){mProcess="";mIsVip="";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(checkbox_allSelected&&!checkbox_serialSelected&&checkbox_freeSelected&&checkbox_vipSelected){mProcess="2";mIsVip="";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(checkbox_allSelected&&!checkbox_serialSelected&&!checkbox_freeSelected&&checkbox_vipSelected){mProcess="2";mIsVip="0";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(checkbox_allSelected&&!checkbox_serialSelected&&checkbox_freeSelected&&!checkbox_vipSelected){mProcess="2";mIsVip="1";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(!checkbox_allSelected&&checkbox_serialSelected&&checkbox_freeSelected&&checkbox_vipSelected){mProcess="1";mIsVip="";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(!checkbox_allSelected&&checkbox_serialSelected&&!checkbox_freeSelected&&checkbox_vipSelected){mProcess="1";mIsVip="0";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}else if(!checkbox_allSelected&&checkbox_serialSelected&&checkbox_freeSelected&&!checkbox_vipSelected){mProcess="1";mIsVip="1";presenter.getBookCategaryList(mCid, mOrder, mProcess, mIsVip, mPage,"10");mAdapter.notifyDataSetChanged();}mWindow.dismiss();}});checkbox_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton button, boolean b) {checkbox_all.setChecked(b? true:false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_all",b);}});checkbox_serial.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton button, boolean b) {checkbox_serial.setChecked(b? true:false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_serial",b);}});checkbox_free.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton button, boolean b) {checkbox_free.setChecked(b? true:false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_free",b);}});checkbox_vip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton button, boolean b) {checkbox_vip.setChecked(b? true:false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_vip",b);}});rl_checkbox_serial.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {boolean checked = checkbox_serial.isChecked();if(checked){checkbox_serial.setChecked(false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_serial",false);}else{checkbox_serial.setChecked(true);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_serial",true);}Log.e("glk", "ipone7pluss");}});rl_checkbox_all.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {boolean checked = checkbox_all.isChecked();if(checked){checkbox_all.setChecked(false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_all",false);}else{checkbox_all.setChecked(true);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_all",true);}Log.e("glk", "ipone7plusa");}});rl_checkbox_free.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {boolean checked = checkbox_free.isChecked();if(checked){checkbox_free.setChecked(false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_free",false);}else{checkbox_free.setChecked(true);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_free",true);}Log.e("glk", "ipone7plusf");}});rl_checkbox_vip.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {boolean checked = checkbox_vip.isChecked();if(checked){checkbox_vip.setChecked(false);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_vip",false);}else{checkbox_vip.setChecked(true);PrefUtils.putBoolean(UiUtils.getContext(),"checkbox_vip",true);}Log.e("glk", "ipone7plusv");}});}

3:动画效果

   //为popWindow添加动画效果mWindow.setAnimationStyle(R.style.popWindow_animation);

进出的动画style

 <style name="popWindow_animation"><item name="android:windowEnterAnimation">@anim/popupwindow_enter</item><item name="android:windowExitAnimation">@anim/popupwindow_exit</item></style>

进出的xml文件

这里写图片描述
这里写图片描述
4:我的pop 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="#fff"android:layout_marginLeft="@dimen/dm200"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:gravity="left"android:text="都市情感"android:padding="@dimen/dm030"android:textColor="@color/editTextColor"android:background="@drawable/selector_green_textview"android:textSize="@dimen/font_size_large_high"android:layout_height="wrap_content"/><Viewandroid:layout_width="match_parent"android:layout_height="@dimen/dm001"android:background="#d2d2d2"/><TextViewandroid:layout_width="match_parent"android:gravity="left"android:text="书籍状态"android:padding="@dimen/dm040"android:textColor="@color/accountColor"android:background="@drawable/selector_green_textview"android:textSize="@dimen/font_size_large"android:layout_height="wrap_content"/>
<RelativeLayoutandroid:id="@+id/rl_checkbox_serial"android:layout_width="match_parent"android:padding="@dimen/dm020"android:background="@drawable/selector_green_textview"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:text="连载"android:layout_marginLeft="@dimen/dm030"android:layout_centerInParent="true"android:textColor="@color/editTextColor"android:textSize="@dimen/font_size_middle"android:layout_alignParentLeft="true"android:layout_height="wrap_content"/><CheckBoxandroid:id="@+id/checkbox_serial"android:layout_width="wrap_content"android:checked="true"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:button="@drawable/check_box_selector"android:layout_height="wrap_content"/>
</RelativeLayout><RelativeLayoutandroid:id="@+id/rl_checkbox_all"android:layout_width="match_parent"android:padding="@dimen/dm020"android:background="@drawable/selector_green_textview"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:text="完本"android:layout_marginLeft="@dimen/dm030"android:layout_centerInParent="true"android:textColor="@color/editTextColor"android:textSize="@dimen/font_size_middle"android:layout_alignParentLeft="true"android:layout_height="wrap_content"/><CheckBoxandroid:id="@+id/checkbox_all"android:checked="true"android:layout_width="wrap_content"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:button="@drawable/check_box_selector"android:layout_height="wrap_content"/></RelativeLayout><Viewandroid:layout_width="match_parent"android:layout_height="@dimen/dm001"android:background="#d2d2d2"/><TextViewandroid:layout_width="match_parent"android:gravity="left"android:text="收费状态"android:padding="@dimen/dm040"android:textColor="@color/accountColor"android:background="@drawable/selector_green_textview"android:textSize="@dimen/font_size_large"android:layout_height="wrap_content"/><RelativeLayoutandroid:id="@+id/rl_checkbox_free"android:layout_width="match_parent"android:padding="@dimen/dm020"android:background="@drawable/selector_green_textview"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:text="免费"android:layout_marginLeft="@dimen/dm030"android:layout_centerInParent="true"android:textColor="@color/editTextColor"android:textSize="@dimen/font_size_middle"android:layout_alignParentLeft="true"android:layout_height="wrap_content"/><CheckBoxandroid:id="@+id/checkbox_free"android:checked="true"android:layout_width="wrap_content"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:button="@drawable/check_box_selector"android:layout_height="wrap_content"/></RelativeLayout><RelativeLayoutandroid:id="@+id/rl_checkbox_vip"android:layout_width="match_parent"android:padding="@dimen/dm020"android:background="@drawable/selector_green_textview"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:text="VIP"android:layout_marginLeft="@dimen/dm030"android:layout_centerInParent="true"android:textColor="@color/editTextColor"android:textSize="@dimen/font_size_middle"android:layout_alignParentLeft="true"android:layout_height="wrap_content"/><CheckBoxandroid:id="@+id/checkbox_vip"android:checked="true"android:layout_width="wrap_content"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:button="@drawable/check_box_selector"android:layout_height="wrap_content"/></RelativeLayout>
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_alignParentBottom="true"android:layout_width="match_parent"android:orientation="horizontal"android:layout_marginBottom="@dimen/dm010"android:layout_height="wrap_content"><Buttonandroid:id="@+id/resetting_button"android:layout_width="0dp"android:layout_weight="1"android:text="重置"android:background="@color/backgroundDark"android:textColor="@color/colorPrimary"android:layout_height="match_parent"/><Buttonandroid:id="@+id/ok_button"android:layout_width="0dp"android:layout_weight="1"android:text="确定"android:background="@color/colorPrimary"android:layout_height="match_parent"/></LinearLayout>
</RelativeLayout>
</LinearLayout>

5:要想解决点击阴影部分弹窗消失,但是又不能触发弹窗下面的recycleview条目的点击事件加上这样几行
不要设置那个外部触摸的监听,因为无论你返回true 还是false,都会出现状况,要么下方按钮点击没响应要么弹窗消失不了要么。。。。很多种都试试了,真恶心

 mWindow.setOutsideTouchable(true);mWindow.setTouchable(true);mWindow.setFocusable(true);

6:有疑问联系18792586740@163.com
福利地址点进来吧

这篇关于popwindow创建以及事件拦截与内部包含checkbox选中的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/743005

相关文章

Spring创建Bean的八种主要方式详解

《Spring创建Bean的八种主要方式详解》Spring(尤其是SpringBoot)提供了多种方式来让容器创建和管理Bean,@Component、@Configuration+@Bean、@En... 目录引言一、Spring 创建 Bean 的 8 种主要方式1. @Component 及其衍生注解

MySQL 数据库表操作完全指南:创建、读取、更新与删除实战

《MySQL数据库表操作完全指南:创建、读取、更新与删除实战》本文系统讲解MySQL表的增删查改(CURD)操作,涵盖创建、更新、查询、删除及插入查询结果,也是贯穿各类项目开发全流程的基础数据交互原... 目录mysql系列前言一、Create(创建)并插入数据1.1 单行数据 + 全列插入1.2 多行数据

MySQL 临时表创建与使用详细说明

《MySQL临时表创建与使用详细说明》MySQL临时表是存储在内存或磁盘的临时数据表,会话结束时自动销毁,适合存储中间计算结果或临时数据集,其名称以#开头(如#TempTable),本文给大家介绍M... 目录mysql 临时表详细说明1.定义2.核心特性3.创建与使用4.典型应用场景5.生命周期管理6.注

MySQL的触发器全解析(创建、查看触发器)

《MySQL的触发器全解析(创建、查看触发器)》MySQL触发器是与表关联的存储程序,当INSERT/UPDATE/DELETE事件发生时自动执行,用于维护数据一致性、日志记录和校验,优点包括自动执行... 目录触发器的概念:创建触www.chinasem.cn发器:查看触发器:查看当前数据库的所有触发器的定

创建springBoot模块没有目录结构的解决方案

《创建springBoot模块没有目录结构的解决方案》2023版IntelliJIDEA创建模块时可能出现目录结构识别错误,导致文件显示异常,解决方法为选择模块后点击确认,重新校准项目结构设置,确保源... 目录创建spChina编程ringBoot模块没有目录结构解决方案总结创建springBoot模块没有目录

IntelliJ IDEA2025创建SpringBoot项目的实现步骤

《IntelliJIDEA2025创建SpringBoot项目的实现步骤》本文主要介绍了IntelliJIDEA2025创建SpringBoot项目的实现步骤,文中通过示例代码介绍的非常详细,对大家... 目录一、创建 Spring Boot 项目1. 新建项目2. 基础配置3. 选择依赖4. 生成项目5.

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

创建Java keystore文件的完整指南及详细步骤

《创建Javakeystore文件的完整指南及详细步骤》本文详解Java中keystore的创建与配置,涵盖私钥管理、自签名与CA证书生成、SSL/TLS应用,强调安全存储及验证机制,确保通信加密和... 目录1. 秘密键(私钥)的理解与管理私钥的定义与重要性私钥的管理策略私钥的生成与存储2. 证书的创建与

linux解压缩 xxx.jar文件进行内部操作过程

《linux解压缩xxx.jar文件进行内部操作过程》:本文主要介绍linux解压缩xxx.jar文件进行内部操作,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、解压文件二、压缩文件总结一、解压文件1、把 xxx.jar 文件放在服务器上,并进入当前目录#

python如何创建等差数列

《python如何创建等差数列》:本文主要介绍python如何创建等差数列的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python创建等差数列例题运行代码回车输出结果总结python创建等差数列import numpy as np x=int(in