Getting the background color of an ImageView

后端 未结 2 614
野趣味
野趣味 2020-12-18 03:01

I have a plain ImageView object colorSquare.

It is straightforward to set the color of the object by calling.

colorSquare.s         


        
2条回答
  •  庸人自扰
    2020-12-18 03:34

    What u can do is

    get ColorDrawable from ImageView.

    ColorDrawable drawable = (ColorDrawable) colorSquare.getBackground();
    

    now

    drawable.getColor()

    will give u the Color.

    This will work only if u have set the Color or else u will get ClassCastException

提交回复
热议问题