简体   繁体   English

Android drawable 在以编程方式更改时变为黑色和白色

[英]Android drawable turns black and white when changed programatically

I have a Floating action button that has a drawable as a source looking like this (the chef button) -我有一个浮动操作按钮,它有一个可绘制的源,看起来像这样(厨师按钮) -

在此处输入图像描述

Later on in my app I change it's source programatically to another source, and then back to the original source with this code -稍后在我的应用程序中,我以编程方式将其源代码更改为另一个源代码,然后使用此代码返回原始源代码 -

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        HomePageActivity.getChefButton().setImageDrawable(getResources().getDrawable(R.drawable.chef_white, getContext().getTheme()));
    } else {
        HomePageActivity.getChefButton().setImageDrawable(getResources().getDrawable(R.drawable.chef_white));
    }

but then it looks like this -但它看起来像这样 -

在此处输入图像描述

Any ideas on how to prevent this?关于如何防止这种情况的任何想法?

Found the solution.找到了解决方案。

I added -我补充说——

  app:tint="@null"

to the floating button and it worked.到浮动按钮,它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM