Get background color of a Layout

Srujan Simha picture Srujan Simha · Feb 8, 2013 · Viewed 66.8k times · Source

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

Answer

Rich picture Rich · Feb 8, 2013

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();