Unknow color Error

I wanted to use app inventor colors in one of the my extension. but when I try to convert Integer Color to hex. it is throwing an exception - Unknown color
My code -

String color = "#"+Integer.toHexString(Colour).substring(2);
textView.setLinkTextColor(Color.parseColor(color));

I really don't know how to solve this.

can you show your block on app

1 Like

Its designer properties.

Okay now I got the solution

What about using this method?

2 Likes

Actually your code isn't wrong, and I think the wrong is how to use the block.

Make the block like this (Add Make Color Block) and I'm sure it will work :

My Sample Code :

@SimpleFunction(description = "")
    public String RGBtoHEX(int color) {
        String colorHex = "#"+Integer.toHexString(color).substring(2);
        return colorHex;
    }
1 Like

Thanks @Salman_Dev @vknow360 :hugs::hugs:
I will try both methods.

1 Like

@Techno_Vedang please close this topic if your problem is resolved :pray: :kissing_heart:

1 Like

I use String.format() method:

String.format("#%06X", 0xFFFFFF & hex)
1 Like

Here is the problem I guess. You're just using the RR in RRGGBB

substring's first argument is the start index. The toHexString call will give the ARGB form of the string so substring(2) here skips the first two characters (the alpha channel).

However, @Techno_Vedang, I don't see why you are serializing the color from an int to a string just to parse it back to an int? It should be sufficient to pass the argb color as an int directly to setLinkTextColor. Could you expand more on what you're trying to accomplish with this code?

2 Likes

It does not matter from where you are calling the code i.e. designer or blocks.
Both will always work if your code is right.

yeah. I wanted to give a custom LinkColor functionality to my Linkify extension