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 Boot统一异常拦截实践指南(最新推荐)

《SpringBoot统一异常拦截实践指南(最新推荐)》本文介绍了SpringBoot中统一异常处理的重要性及实现方案,包括使用`@ControllerAdvice`和`@ExceptionHand... 目录Spring Boot统一异常拦截实践指南一、为什么需要统一异常处理二、核心实现方案1. 基础组件

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

MySQL分表自动化创建的实现方案

《MySQL分表自动化创建的实现方案》在数据库应用场景中,随着数据量的不断增长,单表存储数据可能会面临性能瓶颈,例如查询、插入、更新等操作的效率会逐渐降低,分表是一种有效的优化策略,它将数据分散存储在... 目录一、项目目的二、实现过程(一)mysql 事件调度器结合存储过程方式1. 开启事件调度器2. 创

mysql外键创建不成功/失效如何处理

《mysql外键创建不成功/失效如何处理》文章介绍了在MySQL5.5.40版本中,创建带有外键约束的`stu`和`grade`表时遇到的问题,发现`grade`表的`id`字段没有随着`studen... 当前mysql版本:SELECT VERSION();结果为:5.5.40。在复习mysql外键约

Window Server创建2台服务器的故障转移群集的图文教程

《WindowServer创建2台服务器的故障转移群集的图文教程》本文主要介绍了在WindowsServer系统上创建一个包含两台成员服务器的故障转移群集,文中通过图文示例介绍的非常详细,对大家的... 目录一、 准备条件二、在ServerB安装故障转移群集三、在ServerC安装故障转移群集,操作与Ser

Window Server2016 AD域的创建的方法步骤

《WindowServer2016AD域的创建的方法步骤》本文主要介绍了WindowServer2016AD域的创建的方法步骤,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一、准备条件二、在ServerA服务器中常见AD域管理器:三、创建AD域,域地址为“test.ly”

Python在固定文件夹批量创建固定后缀的文件(方法详解)

《Python在固定文件夹批量创建固定后缀的文件(方法详解)》文章讲述了如何使用Python批量创建后缀为.md的文件夹,生成100个,代码中需要修改的路径、前缀和后缀名,并提供了注意事项和代码示例,... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果5.

使用IntelliJ IDEA创建简单的Java Web项目完整步骤

《使用IntelliJIDEA创建简单的JavaWeb项目完整步骤》:本文主要介绍如何使用IntelliJIDEA创建一个简单的JavaWeb项目,实现登录、注册和查看用户列表功能,使用Se... 目录前置准备项目功能实现步骤1. 创建项目2. 配置 Tomcat3. 项目文件结构4. 创建数据库和表5.

使用SpringBoot创建一个RESTful API的详细步骤

《使用SpringBoot创建一个RESTfulAPI的详细步骤》使用Java的SpringBoot创建RESTfulAPI可以满足多种开发场景,它提供了快速开发、易于配置、可扩展、可维护的优点,尤... 目录一、创建 Spring Boot 项目二、创建控制器类(Controller Class)三、运行

JAVA中整型数组、字符串数组、整型数和字符串 的创建与转换的方法

《JAVA中整型数组、字符串数组、整型数和字符串的创建与转换的方法》本文介绍了Java中字符串、字符数组和整型数组的创建方法,以及它们之间的转换方法,还详细讲解了字符串中的一些常用方法,如index... 目录一、字符串、字符数组和整型数组的创建1、字符串的创建方法1.1 通过引用字符数组来创建字符串1.2