Using color and color.darker in Android?

后端 未结 4 1757
傲寒
傲寒 2020-12-02 09:07

Okay, so I have an integer variable in my application. It\'s the value of a color, being set by a color picker in my preferences. Now, I need to use both that color and a da

4条回答
  •  独厮守ぢ
    2020-12-02 09:51

    Here is what I created:

    /**
     * Returns darker version of specified color.
     */
    public static int darker (int color, float factor) {
        int a = Color.alpha( color );
        int r = Color.red( color );
        int g = Color.green( color );
        int b = Color.blue( color );
    
        return Color.argb( a,
                Math.max( (int)(r * factor), 0 ),
                Math.max( (int)(g * factor), 0 ),
                Math.max( (int)(b * factor), 0 ) );
    }
    

提交回复
热议问题