I tried to achieve this but I am only able to achieve to fill object (shape). My requirement is to change text color along with shape filling.
Shape can be filled with percentage like till
10% to 50% = Green
51% to 80% = Yellow
81% to 100% = Red
When Yellow color fills background of ":" in shape, it will change color to "White" which is previously "Yellow". Size of this shape is also dynamic.
What I tried and achieved?
I am able to fill shape with percentage but failed to change color when it reaches to edge of text.
Right-click the shape that you want to add a pattern fill to and select Format Shape. In the Format Shape pane, click Fill, and then click Pattern Fill. Select a pattern, and if you like, click the arrows next to Foreground and Background and select a color combination.
Change the inside (fill) colorClick Shape Fill, and under Theme Colors, pick the color you want. Select the shape or text box. On the Drawing Tools Format tab, click Shape Fill > More Fill Colors. In the Colors box, either click the color you want on the Standard tab, or mix your own color on the Custom tab.
I wrote a custom view. You get this double color effect using Path APIs. But for Android 1+ compatibility, you should use Region API and above Kitkat (19+) you can use just Path API.
Let's go through the concept of how to achieve this effect step by step:
If you are using API 19+, this is how the critical code snippet looks like:
croppedProgressPath.op(progressPath, textPath, Path.Op.DIFFERENCE);
croppedProgressPath.op(progressStrokePath, Path.Op.INTERSECT);
————————————
croppedTextPath.op(textPath, progressPath, Path.Op.DIFFERENCE);
Lines here and here.
I’ve written a Proof of Concept for this project called Diffre on Github. If you wanna test it out first, all the code is in this repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With