Get associated image (Drawable) in ImageView android

前端 未结 8 896
心在旅途
心在旅途 2021-02-07 18:34

I have set an image to an ImageView control in android:

iv.setImageResource(R.drawable.image1);

I want to get this associated Drawab

8条回答
  •  情书的邮戳
    2021-02-07 18:53

    if ((holder.fav.getDrawable().getConstantState()) == context.getResources().getDrawable(R.drawable.star_blank).getConstantState() ) {
    
      holder.fav.setImageDrawable(context.getResources().getDrawable(R.drawable.star_fill));
    
    // comparison is true
    } 
    
    

    //getConstantState() is the key

提交回复
热议问题