applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
17 stars 6 forks source link

How to load color resource using Resource ID in HarmonyOS? #10

Closed sohamvg closed 3 years ago

sohamvg commented 3 years ago

Describe the query

I am building a HarmonyOS application and want to load color values that I have placed in the resources folder in resources/base/element/color.json. How can I load this color in my Java class?

In Android we can use the getColor() function for this:

context.getResources().getColor(R.color.colorID);

What is the alternative for this in HarmonyOS?

Create the query with harmonyos tag in stackoverflow and share the link here:

https://stackoverflow.com/questions/68542335/how-to-load-color-resource-using-resource-id-in-harmonyos

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.303 SDK API version: 5 SDK version: 2.1.1.21 Device: Not Required Device OS version: Not Required

kanaksony commented 3 years ago

Already replied and accepted on Stackoverflow, hence good to close!