I want to find the background color of a Layout from my code. Is there any way to find it? something like linearLayout.getBackgroundColor()
?
To get background color of a Layout: LinearLayout lay = (LinearLayout) findViewById(R. id. lay1); ColorDrawable viewColor = (ColorDrawable) lay.
Create background color. By default each activity in Android has a white background. To change the background color, first add a new color definition to the colors. xml file in the values resource folder like the following.
This can only be accomplished in API 11+ if your background is a solid color.
int color = Color.TRANSPARENT; Drawable background = view.getBackground(); if (background instanceof ColorDrawable) color = ((ColorDrawable) background).getColor();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With