获取布局的背景颜色布局、颜色、背景

2023-09-06 13:20:55 作者:我的命运我主宰

我想找到一个布局的背景颜色从我的code。有没有办法找到它?像 linearLayout.getBackgroundColor()

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

推荐答案

这只能完成API 11+,如果你的背景是纯色的。

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