I have a scrollView
in my Activity
,the background of scrollView
is of multiple colours.
<ScrollView ---------->
<RelativeLayout -------------/>
</ScrollView>
To my RelativeLayout
I have added Views dynamically.
inflated xml:
<RelativeLayout --------------android:background="some transparent image">
<TextView --------- ---------/>
</RelativeLayout>
I want my Text coloured to be same as Background colour. I have tried for the solution in many ways but could not succeed.
In iOS for achieving this they have used RSMaskedLabel
(third party class), but I didn’t find anything similar to this in Android.
Still I didnt find any solution,can anyone help me please. I tried by using Bitmaps and Canvas but didnt worked for me.
Some guidelines how to achieve this with custom
TextView
:TextView
componentBitmap
andCanvas
where you draw background and textCanvas
(e.g.Color.argb(80, 255, 255, 255)
)Paint
having modePorterDuffXfermode(Mode.CLEAR)
(Remember: Only allocateBitmap
andCanvas
once) since you draw it intoBitmap
Bitmap
intoTextViews
canvasHere is some sample code to get started with:
If you are setting text dynamically, you will need to reset
mBitmapToDraw
in order to get it refreshed.