Tencent / QMUI_Android

提高 Android UI 开发效率的 UI 库
http://qmuiteam.com/android
Other
14.4k stars 2.67k forks source link

QMUITabIcon 中改变 drawable alpha 导致其他地方使用图片资源异常 #592

Open KeWeize opened 5 years ago

KeWeize commented 5 years ago

运行环境

具体问题描述

QMUITab 设置了 normalDrawable 和 selectedDrawable 之后,生成的 QMUITabIcon 在执行 selected 切换时会分别改变两个 drawable 的 alpha。如图中 Components Tab 被选中时,其 normalDrawable alpha 被设置为 0。这时候会导致,如果在其他地方使用这个 drawable 对应的资源图片时,比如在 mImageView.setImageResource(R.mipmap.icon_tabbar_component_normal),会出现设置的 Drawable 是透明的(这貌似是 Android 本身的问题,setImageResource(R.mipmap.icon_tabbar_component_normal) 时生成的 drawable 貌似复用了内存中被 QMUITabIcon 改变了 alpha 的 drawable)。

问题截图

QQ截图20190509145221

cgspine commented 5 years ago

调用一下 drawable.mutate() 就好

.setNormalDrawable(normalDrawable.mutate())
.setSelectedDrawable(selectedDrawable.mutate())
KeWeize commented 5 years ago

大佬666... 不过是否在 QMUITabBuilder或者QMUITabIcon加会好点?

cgspine commented 5 years ago

恩,后面会补上这个