Closed chakrichokkaku closed 3 years ago
First you have to build an Element using some color,
public static Element buildElementByColor(int color) {
ShapeElement drawable = new ShapeElement();
drawable.setShape(ShapeElement.RECTANGLE);
drawable.setRgbColor(RgbColor.fromArgbInt(color));
return drawable;
}
later you have set the built element using setBackground API
component.setBackground(buildElementByColor((Color.DKGRAY).getValue()));
I am working on a HarmonyOs project in that I wanted to set the background color of the component. In Android we have a function setBackgroundColor() in the View class, this can be done as shown below.
How can I set background color to a component in HarmonyOs?
Link to StackOverflow https://stackoverflow.com/questions/68588609/what-is-the-alternative-in-harmony-os-for-function-setbackgroundcolor-on-view
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