Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现一个关于TextView背景的bug #1

Open
y-zx opened this issue Nov 4, 2019 · 0 comments
Open

发现一个关于TextView背景的bug #1

y-zx opened this issue Nov 4, 2019 · 0 comments

Comments

@y-zx
Copy link

y-zx commented Nov 4, 2019

android:background="@color/colorAccent"
android:id="@+id/testview"

TextView 在xml文件里面设置了背景颜色(一个粉色),

broccoli.addPlaceholders(this, R.id.testview);
broccoli.show();
Activity里面设置背景,此时TextView背景色变成了框架内默认的 #dddddd。

但在调用broccoli.removeAllPlaceholders()后,TextView的背景颜色还是 默认的#dddddd。

查看源码发现,
placeholderPreStateSaver.setRestoredBackgroundDrawable(textView.getBackground());
存储的是textView原Drawable对象,
随后调用
if (parameter.getColor() != 0){
view.setBackgroundColor(parameter.getColor());
return;
}

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) {
if (mBackground instanceof ColorDrawable) {
((ColorDrawable) mBackground.mutate()).setColor(color);
computeOpaqueFlags();
mBackgroundResource = 0;
} else {
setBackground(new ColorDrawable(color));
}
}
发现把颜色设置给了textView原Drawable对象,导致被存储的原Drawable颜色被改变,
所以broccoli.removeAllPlaceholders()恢复的颜色是默认的#dddddd,

使用如下方式生成一个新Drawable对象,则不会对原Drawable对象造成影响,
broccoli.addPlaceholder(new PlaceholderParameter.Builder()
.setView(findViewById(R.id.testview))
.setDrawable(new ColorDrawable(Color.parseColor("#dddddd")))
.build());

可能还有其他地方也会有同样问题(直接储存原对象,设置原对象),希望作者在README声明一下,或者更新解决下这个问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant