首页 > 解决方案 > 检查 ImageView 是否应用了 ColorFilter?

问题描述

所以我正在尝试在我的社交应用程序中点赞,以及是否确定是否已经应用了点赞我试图查看滤色器

因此,如果帖子不受欢迎,它将是白色的,否则我将在按下它的同时执行此行

buttonlikesHeart.setColorFilter(Color.rgb( 255,0,0 ));

这很好用,但是当我想检查它是否已经有这个特定的滤色器时:

if(buttonlikesHeart.getColorFilter() == Color.rgb( 255,0,0 )){

}

它告诉我 == 不能应用于 Colorfilter 和 int ?

如果我这样做

if(buttonlikesHeart.getColorFilter( Color.rgb( 255,0,0 ))){

}

它告诉我 ImageView 中的 getColorFilter 不能应用于 int

解决方案?

标签: javaandroidandroid-studioandroid-layoutimageview

解决方案


首先,确保您在 ImageView Not a Button 中应用它。

"buttonlikesHeart" 它应该是一个 ImageView

 if(imageView.getColorFilter() == null)
                    {
                        Log.i("The Image has no Filter", "No filter");
                        //Your rest of code here.
                    }
                    else
                    {
                        Log.i("The Image is Filtered", "Filtered");
                        //Your rest of code here.
                    }

推荐阅读