Java 如何将返回的int值从ColorDrawable';将getColor()转换为RGB?

Java 如何将返回的int值从ColorDrawable';将getColor()转换为RGB?,java,android,colors,android-studio,Java,Android,Colors,Android Studio,下面是检索活动背景颜色的代码片段。然而,getColor返回一个int值,并且似乎没有办法修改它以返回一个更标准的格式来处理和修改 setContentView(R.layout.activity_test); View root = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0); int color = Color.TRANSPARENT; Drawable background

下面是检索活动背景颜色的代码片段。然而,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();

在这种特殊情况下,活动的背景色最初定义为getColor()返回为-16737844的XML文件中的android:background=“#0099cc”。但是,我想通过做一些事情来改变它,比如随着时间的推移逐渐改变颜色的rgb值[即rgb(initialRVal+1,initialGVal+1,initialBVal+1)]。这需要我以某种方式将-16737844转换为一组RGB值,但似乎没有这样做的方法。

您想将十六进制颜色值转换为RGB

int red = (color >> 16) & 0xFF;
int green = (color >> 8) & 0xFF;
int blue = (color >> 0) & 0xFF;

要将十六进制颜色值转换为RGB

int red = (color >> 16) & 0xFF;
int green = (color >> 8) & 0xFF;
int blue = (color >> 0) & 0xFF;