【发布时间】:2014-09-20 04:39:35
【问题描述】:
所以我有以下 sn-p 代码来检索活动的背景颜色。但是,getColor 返回一个 int 值,似乎没有办法修改它以返回一个更标准的格式来使用和修改。
setContentView(R.layout.activity_test);
View root = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
int color = Color.TRANSPARENT;
Drawable background = root.getBackground();
if (background instanceof ColorDrawable)
color = ((ColorDrawable) background).getColor();
在这种特殊情况下,活动的背景颜色最初在 XML 文件中定义为 android:background="#0099cc",getColor() 返回为 -16737844。但是,我想通过做一些事情来改变它,比如随着时间的推移逐渐改变颜色的 rgb 值[即rgb(initialRVal+1,initialGVal+1,initialBVal+1)]。这需要我以某种方式将 -16737844 转换为一组 RGB 值,但似乎没有办法这样做。
【问题讨论】:
标签: java android colors android-studio