获取布局的背景颜色 [英] Get background color of a Layout

查看:366
本文介绍了获取布局的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一个布局的背景颜色从我的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();

这篇关于获取布局的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆