获得色彩-INT的颜色资源 [英] Get color-int from color resource

查看:110
本文介绍了获得色彩-INT的颜色资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让一个颜色INT从颜色资源? 我想获得的资源(R.color.myColor)定义,这样我可以设置三个seekbars值到特定级别的彩色的单独的红色,蓝色和绿色组成部分。


有关另一个用例的详细信息,可以帮助表面在搜索结果中这个问题,我想申请阿尔法在我的资源定义的颜色。使用@税务总局的正确答案:

  INT字母= ... // 0-255,基于一些业务逻辑的计算
INT actionBarBackground = getResources()的getColor(R.color.actionBarBackground)。
INT actionBarBackgroundWithAlpha = Color.argb(α,
        Color.red(actionbarBackground)
        Color.green(actionbarBackground)
        Color.blue(actionbarBackground));
 

解决方案

您可以使用:

  getResources()的getColor(R.color.idname)。
 

请点击这里了解如何定义自定义颜色:

<一个href="http://sree.cc/google/android/defining-custom-colors-using-xml-in-android">http://sree.cc/google/android/defining-custom-colors-using-xml-in-android

Is there a way to get a color-int from a color resource? I am trying to get the individual red, blue and green components of a color defined in the resource (R.color.myColor) so that I can set the values of three seekbars to a specific level.


For more information on another use-case that may help surface this question in search results, I wanted to apply alpha to a color defined in my resources. Using @sat's correct answer:

int alpha = ... // 0-255, calculated based on some business logic
int actionBarBackground = getResources().getColor(R.color.actionBarBackground);
int actionBarBackgroundWithAlpha = Color.argb(alpha,
        Color.red(actionbarBackground),
        Color.green(actionbarBackground),
        Color.blue(actionbarBackground));

解决方案

You can use:

getResources().getColor(R.color.idname);

Check here on how to define custom colors:

http://sree.cc/google/android/defining-custom-colors-using-xml-in-android

这篇关于获得色彩-INT的颜色资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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