Get backgroundcolor of elemt in Android studio java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Get backgroundcolor of elemt in Android studio java

I know, how to set: elementID.setBackgroundColor(Color.BLUE) Now I want to check: if color is blue, then set White I thought: if(elementID.getBackgroundColor == Color.BLUE) but there is no such thing as "getBackgroundColor" So how to get the BG-Color of the element (EditText in my case)? Thank you in advance!

15th Oct 2020, 10:53 AM
Fu Foy
Fu Foy - avatar
2 Answers
+ 2
I do something like this, int color=((ColorDrawable)element.getBackground()).getColor(); If(color==Color.BLUE){}
15th Oct 2020, 4:20 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 1
Thank you!
16th Oct 2020, 6:58 AM
Fu Foy
Fu Foy - avatar