Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get background color of a Layout

I want to find the background color of a Layout from my code. Is there any way to find it? something like linearLayout.getBackgroundColor()?

like image 884
Srujan Simha Avatar asked Feb 08 '13 18:02

Srujan Simha


People also ask

How do you get the background color on a view?

To get background color of a Layout: LinearLayout lay = (LinearLayout) findViewById(R. id. lay1); ColorDrawable viewColor = (ColorDrawable) lay.

How do I change the default background color in Android Studio?

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.


1 Answers

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(); 
like image 191
Rich Avatar answered Sep 29 '22 20:09

Rich