How to get the color of view. If there isn't any way please write the code for it.
Asked
Active
Viewed 351 times
-1
-
Do you have the color available in any form? – Suhayl SH Feb 08 '17 at 09:25
-
Refer this link for it http://stackoverflow.com/a/6540378/3946958 ..Before asking the question here ,plz search about the topic properly – Ravindra Kushwaha Feb 08 '17 at 09:26
-
how do you set the color of view, android:background? – Tang Ke Feb 08 '17 at 09:28
-
Not sure if your are asking for something like this: [Get background color of a Layout](http://stackoverflow.com/a/14779461/1113211) – salmanwahed Feb 08 '17 at 09:30
-
@RavindraKushwaha I search but I didn't find any answer so I asked here. – CatCoder Feb 08 '17 at 09:32
-
@TangKe I set it with view.setBackgroundColor – CatCoder Feb 08 '17 at 09:33
1 Answers
0
If you use view.setBackgroundColor()
method to set the color of view,
view will auto create a ColorDrawable
instance to set to the view,
you just need to call int color = ((ColorDrawable)view.getBackground()).getColor()
to retrieve the color.
If you want to get the color value in hexadecimal format, just invoke 'Integer.toHexString(color)'
hope this can help you

Tang Ke
- 1,508
- 12
- 12