【问题标题】:DrawableCompat.setTint() no longer working with appcompat-v7 23.2.1DrawableCompat.setTint() 不再适用于 appcompat-v7 23.2.1
【发布时间】:2016-03-24 11:06:18
【问题描述】:

以前在 23.2.0 中可以设置色调。当我将版本更改为 23.2.1 时,以下代码不再着色我的 ImageView。

我有一个定义为

的图像视图列表
List<ImageView> statusStage = new ArrayList<>();

然后我使用以下方法更新图像色调。

public void setStatusStage(int stageComplete, int colorOn ) {
    for (int i = 0; i < statusStage.size(); i++) {
        ImageView ss = statusStage.get(i);
        Drawable dr = DrawableCompat.wrap(ss.getDrawable());
        DrawableCompat.setTint(dr, colorOn);
        print("stage Complete:" + stageComplete+", "+i);
    }
}

现在setTint的方式不一样了吗? 我需要更改我的代码以使其适用于新版本?

有 bug 的 appcompat 版本。

compile 'com.android.support:appcompat-v7:23.2.1'

【问题讨论】:

    标签: android android-support-library android-appcompat


    【解决方案1】:

    您好像错过了给setImageDrawable() 打电话。

    public void setStatusStage(int stageComplete, int colorOn ) {
        for (int i = 0; i < statusStage.size(); i++) {
            ImageView ss = statusStage.get(i);
            Drawable dr = DrawableCompat.wrap(ss.getDrawable());
            DrawableCompat.setTint(dr, colorOn);
            print("stage Complete:" + stageComplete+", "+i);
            ss.setImageDrawable(dr); //this part
        }
    }
    

    我还建议你使用setTintList() 而不是setTint() 来表示状态。

    【讨论】:

    • 该错误在 ss.setImageDrawable(dr) 中仍然存在;这个错误只发生在 23.2.1 中,而不是早期版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    相关资源
    最近更新 更多