applibgroup / HarmonyOS-Knowledgebase

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

What is the alternative in harmony OS for imageview.setColorFilter in android? #47

Closed anshulgoel72 closed 3 years ago

anshulgoel72 commented 3 years ago

Describe the query

In android, we can change the color of the drawable by using setColorFilter method. How do we do that in HarmonyOS?

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

https://stackoverflow.com/questions/68590097/what-is-the-alternative-in-harmony-os-for-imageview-setcolorfilter-in-android

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

samuel-abhishek commented 3 years ago

setColorFilter(Color) is not directly supported in HMOS. But you may check the below callback in ohos.agp.components.element.Element class,

public void setColorMatrix​(ColorMatrix matrix)

which will also change the color of the element(which is equivalent to drawable in android). Please note, here you need to pass the ColorMatrix object as the argument. Please check this documentation for more info``