需求是将系统中
底部的白色背景改成黑色背景
=》
查找工程看
底部调用的
代码是公共
代码位于,
idh.code\
vendor\sprd\platform\frameworks\support\featurebar\*
于是将color由white
修改为black,以为就好了.结果发现大部分界面如预期都好了,可是桌面部分应用
底部显示还是白色,录音机应用
显示为半灰色。查找
代码发现这些问题界面中并未对此背景进行二次设置color,再这些界面重新设置color又好了,百思不得其解.......
今天查找了一天原因,终于从这个坑里面拔出来了……
原因是
android中从同
一个资源
文件中加载出来的drawable会共享状态,如果你加载出来多个drawable,当改变了其中
一个的状态时,其他drawable的状态也会相应改变。
在待机桌面界面的时候,对
底部的背景alpha进行了
修改:
FeatureBarUtil.setBackgroundAlpha(mFeatureBarHelper,
Math.round(255 * (visible ? mSoftB
aralpha : 1.0f)));
public static void setBackgroundAlpha(FeatureBarHelper fbh, int alpha) {
Drawable bg = getBackground(fbh);
if (bg != null) {
bg.setAlpha(alpha);
}
}
解决方案:
方案解释:
/**
* Make this drawable mutable. This operation cannot be reversed. A mutable
* drawable is guaranteed to not share its state with any other drawable.
* This is especially useful when you need to modify properties of drawables
* loaded from resources. By default, all drawables instances loaded from
* the same resource share a common state; if you modify the state of one
* instance, all the other instances will receive the same modification.
*
* Calling this method on a mutable Drawable will have no effect.
*
* @return This drawable.
* @see ConstantState
* @see #getConstantState()
*/
public Drawable mutate() {
return this;
}
翻译过来就是:
使这个drawable变得状态不定。这个操作不能还原(变为不定后就不能变为原来的状态)。
一个状态不定的drawable可以保证它不与其他任何
一个drawabe共享它的状态。这对于你需要更改从同一资源加载来的drawable的
属性时非常有用。
默认情况下,所有的从同一资源(R.drawable.XXX)加载来的drawable实例都共享
一个共用的状态,如果你更改
一个实例的状态,其他所有的实例都会收到相同的
通知。
这个
方法对于已经是mutable的drawable没有
效果。
修改方案和解释参考
https://blog.csdn.net/bzlj2912009596/article/details/79707023
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。