【问题标题】:Check if ImageView has ColorFilter applied or not?检查 ImageView 是否应用了 ColorFilter?
【发布时间】:2020-09-28 00:02:07
【问题描述】:

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

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

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

解决方案?

【问题讨论】:

    标签: java android android-studio android-layout imageview


    【解决方案1】:

    首先,确保您在 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.
                        }
    

    【讨论】:

      猜你喜欢
      • 2012-04-24
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2019-12-24
      相关资源
      最近更新 更多