kotlin中介绍PopupWindow中textView?.isSelected = false的不变色bug
来源:互联网 发布:input失去焦点触发js 编辑:程序博客网 时间:2024/06/07 03:45
在kotlin中的写法和java中基本一样 因为经常用到就直接粘在这里了
private fun showSellerPop() { if (mPopupWindow == null) mPopupWindow = PopupWindow(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply { val inflate = View.inflate(activity, R.layout.layout_popwin_supplier_list, null) setBackgroundDrawable(ColorDrawable()) contentView = inflate val recyclerView = inflate.find<RecyclerView>(R.id.popwin_list_view) recyclerView?.layoutManager = GridLayoutManager(activity, 4, GridLayoutManager.VERTICAL, false) sellerAdapter = object : CommonRecycleViewAdapter<BussinessTypeData>(activity, R.layout.item_popwin_list, mMenuData1) { override fun convert(helper: ViewHolderHelper?, good: BussinessTypeData, position: Int) { val textView = helper?.getView<TextView>(R.id.item_popwin_tv) val class_name = good.class_name val class_id = good.class_id textView?.text = class_name textView?.isSelected = false if (class_name == titleBarselectimg?.text.toString()) { //textView?.setBackgroundResource(R.drawable.item_popwin_select_bg) //textView?.setTextColor(Color.parseColor("#ffffffff")) textView?.isSelected = true } textView?.onClick { searchBean.class_id = class_id titleBarselectimg?.text = class_name dismiss() toSearch() notifyDataSetChanged() } } } recyclerView?.adapter = sellerAdapter isFocusable = true isOutsideTouchable = true } mPopupWindow?.showAsDropDown(line, 0, 0) }
其实我最想说是convert部分,说也说不明白直接看下图
这种点击状态选择器相信大家都可以随便写了吧,不过就是这个简单的状态选在器却困扰了我很久,以前的项目中都是用的CheckBox替代TextView的。
这是TextView的标准选择器写法
看清楚顺序从上到下 , 下面两个默认状态一定写最下面
<item android:color="@color/rgb_85_85_85"></item><item android:drawable="@drawable/item_popwin_bg"></item>
<TextView android:id="@+id/item_popwin_tv" android:layout_width="@dimen/dimen_80dp" android:layout_height="@dimen/dimen_30dp" android:background="@drawable/item_popwin_selector" android:gravity="center" android:singleLine="true" android:text="酒店" android:textColor="@color/item_grid_selector" android:textSize="@dimen/textSize_14" />
item_popwin_selector
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/item_popwin_select_bg" android:state_selected="true"></item> <item android:drawable="@drawable/item_popwin_select_bg" android:state_pressed="true"></item> <item android:drawable="@drawable/item_popwin_bg"></item></selector>
item_grid_selector
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/white" android:state_pressed="true"></item> <item android:color="@color/white" android:state_selected="true"></item> <item android:color="@color/rgb_85_85_85"></item></selector>
override fun convert(helper: ViewHolderHelper?, good: BussinessTypeData, position: Int) { val textView = helper?.getView<TextView>(R.id.item_popwin_tv) val class_name = good.class_name val class_id = good.class_id textView?.text = class_name textView?.isSelected = false if (class_name == titleBarselectimg?.text.toString()) {//textView?.setBackgroundResource(R.drawable.item_popwin_select_bg)//textView?.setTextColor(Color.parseColor("#ffffffff")) textView?.isSelected = true } textView?.onClick { searchBean.class_id = class_id titleBarselectimg?.text = class_name dismiss() toSearch() notifyDataSetChanged() } }
看客老爷可以说我说的话啰嗦是废话,可是恰恰就是最细微的bug才难以发现,慢慢积累成为不得不面对的问题。所以在此mark一下,提醒自己,也希望正在为此困惑的童鞋可以发现并解决这个问题。
sellerAdapter 是另外一个刷新库
我还写了一个PopWindow工具类下次加进来
阅读全文
0 0
- kotlin中介绍PopupWindow中textView?.isSelected = false的不变色bug
- textview中实现字体变色
- 安卓7.0中popupWindow的BUG
- Kotlin开发中遇到的bug
- NavigationBar的第二中方法,图片变色,文字不变色
- selenium中isEnable()、isDisplayed()和isSelected()
- 解决含有Textview布局在viewpager等横向滑动中滑动不流畅的bug
- Android7.0中关于popupWindow的bug解决办法
- android中listview点击item不变色的问题
- html 中如何实现背景变色而字体不变色
- android中Fragment中弹不出popupwindow的问题处理
- ClickableSpan android:textColorHighlight="@color/colora4e0db" 无效 不变色 TextView
- ValidateRequest=false 在.Net 4.0 中不管用
- ValidateRequest=false 在.Net 4.0 中不管用
- Android中TextView中文字死活不滚的解决办法
- Android中TextView中内容不换行的解决方法
- android中TextVIew中你不知道的属性
- Android中TextView中内容不换行的解决方法
- Swiper的学习笔记
- SonarQube 在linux 异常关机后无法正常启动
- 【iOS笔记-1】使用Cocoapods安装Alamofire
- Microsoft Office 2007 永久激活序列号 (密钥)
- linux 命令学习笔记
- kotlin中介绍PopupWindow中textView?.isSelected = false的不变色bug
- css针对不同版本ie
- JSONObject相关依赖架包下载(Maven依赖下载)
- Java并发编程:Synchronized及其实现原理
- Docker学习笔记 — k8s部署
- Linux 安装redis单机
- SpannableString与SpannableStringBuilder
- Vue 2.0 的数据依赖原理解析
- 《奇思妙想:15位计算机天才及其重大发现》【PDF】下载