HOW TO CHANGE ALPHA COLOR OBJECT?

Brad Pitt

Total Post:61

Points:429
Posted by  Brad Pitt
Java 
 850  View(s)
Ratings:
Rate this:
Is there a way to add aplha to color that i can get from a color string. Because now i can draw my color without the alpha by using the following code

CircleOptions options = new CircleOptions().center(new LatLng(car.getLatitude(), car.getLongitude()))

.radius(car.getRadius())

.strokeColor(Color.argb(50, 232, 245, 248))

.strokeWidth(2)

.fillColor(Color.parseColor(car.getColorString()));

This works fine. But i want to make the color more transparent. Is there a good way to add alpha do this color because i can only get out a "ColorString"

  1. Maria Susan

    Post:29

    Points:107
    Re: How to change alpha color object?

    Color is represented as a int and you can represent it with hex notation like 0xAARRGGBB, which means Alpha, Red, Green, Blue. So each value can be 0 to 255.

    Thus, what you want can be achieved with some bit operations.

    If you want reset alpha value then,

    int newColor = 0x10000000 | (Color.parseColor(car.getColorString()) & 0xFFFFFF);
    (0x10000000 means new alpha value - 16 which is about 6.274% alpha because 100% is 255)
    (0xFFFFFF means we take only rgb value from a color)

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!