以十六进制获取视图的背景颜色

问题描述 投票:1回答:2

我想以十六进制格式获取视图的背景颜色。

例如考虑qazxsw poi我的例外回报值是qazxsw poi。

我怎么能这样做?

谢谢。

android user-interface view colors background
2个回答
2
投票
int getViewBackgroundColor(View view)

获得整数类型的颜色后,你必须转换为hexa

0Xff256e78

希望这可以帮助..


1
投票

以下代码将获取视图的背景颜色并将其转换为颜色的int表示形式。

LinearLayout layout = (LinearLayout) findViewById(R.id.lay1);
ColorDrawable viewColor = (ColorDrawable) layoutgetBackground();
int colorId = viewColor.getColor();
© www.soinside.com 2019 - 2024. All rights reserved.