1

I am trying to set color from a json color array to my custom menu background.

addMenuItem(int bgColor);

json color array =>

[ [ "B71C1C", "C62828"],[ "B71C1C", "C62828"] ] 

Color String is getting correctly from json

String colorString = "#" + mColors.getJSONArray(i%2).getString(i%2); gives #B71C1C;

While convert it to integer int parseColor = Color.parseColor(colorString); and passing to above menu background;

ie;addMenuItem(parseColor);

I'm getting

android.content.res.Resources$NotFoundException: Resource ID #0xffb71c1c

I think addMenuItem will accept int only from resource. How can I set color from my JSON color file.

1 Answer 1

4

That's because you are throwing in a number and the Android framework tries to find a resource for that (R.color) which doesn't exist. You should convert that number to a Color object, using Color.argb(int,int,int,int) for example

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.