Get associated image (Drawable) in ImageView android

前端 未结 8 908
心在旅途
心在旅途 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:52

    You can get the drawable like

    Drawable myDrawable = iv.getDrawable();
    

    You can compare it with a drawable resource like

    if(iv.getDrawable()==getResources().getDrawable(R.drawable.image1)){
        //do work here
    }
    

提交回复
热议问题