I am creating a custom component in HarmonyOS using Java SDK, Where I need one attribute to get Element(i.e. VectorElement or png format icon) as input from xml layout file.
for ex:
ohos:sliderIcon="$graphic:custom_icon" (VectorElement)
ohos:sliderIcon="$media:ic_arrow" (PNG format icon)
Now I am getting element in custom component class like this
Element sliderIcon = attrSet.getAttr(Attribute.SLIDER_ICON).isPresent()
? attrSet.getAttr(Attribute.SLIDER_ICON).get().getElement()
: new VectorElement(getContext(), ResourceTable.Graphic_slidetoact_ic_arrow);
but, above code is working only for VectorElement icon NOT for PNG format icon.
And I am able to set both VectorElement and PNG format icon at runtime from java code as follow:
For VectorElement:
Element sliderIcon = new VectorElement(getContext(), ResourceTable.Graphic_custom_icon);
For PNG format icon:
//You can set png format icon using PixelMapElement.
try {
Element sliderIcon = new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_ic_arrow));
} catch (IOException | NotExistException e) {
e.printStackTrace();
}
So my question is
How to get PNG format icon as a attribute in custom component?
OR
How to get resource/reference id of passed Element?