Reputation: 96
I Have an android program with a bunch of text views. Initially, all of these views have no shadow.
when I press a specific toggle button, I want theses textViews to stand out.
Ideally, I wanted to add a text shadow glow effect to them. this I have successfully done without a problem with textView.setShadowLayer(radius, dx, dy, color)
The problem is, if I press the same toggle button again (which makes the shadows appear), I need to remove the shadows so the text isn't highlighted anymore.
I have tried to set the shadow layer to radius 0 and transparent colors #00FFFFFF, #00000000, and colors #FFFFFFFF, #FF000000. However, none of these set the textView back to the original way it appeared.
any ideas on how to remove the shadow. (I don't really have to remove it, i just want the text to appear the same way as before adding it)
the main goal is to use the toggle button to turn on/off text highlighting for specific textViews and I am open to other methods than using a shadow. Ideally I would like to use a shadow, but any other ideas to highlight the text are fine.
(this part was appended after the answer I received with textLayer.setShadow(0,0,0,0);
i am using this style for textView in the layout xml
<style name="second">
<item name="android:textColor">@drawable/buttonBabyBlue</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">@dimen/second_text_size</item>
<item name="android:lines">1</item>
<item name="android:background">@drawable/baseGray</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">8.5</item>
<item name="android:gravity">bottom|left</item>
<item name="android:layout_gravity">bottom</item>
</style>
when i press the button which makes the view have a shadow
text.setShadowLayer(GLOW_RADIUS, GLOW_DX, GLOW_DY, R.drawable.buttonBabyBlue);
text.setTextColor(R.drawable.baseGray);
then to remove the shadow
text.setShadowLayer(0, 0, 0, 0);
text.setTextColor(R.drawable.buttonBabyBlue);
that is annoying i have pictures to show and uploaded them but they won't let me show them for fear of spam
Upvotes: 3
Views: 8109
Reputation: 167
textView.getPaint().clearShadowLayer();
textView.invalidate();
This worked for me.
Upvotes: 2
Reputation: 24235
Call textview.setShadowLayer(0,0,0,0)
to clear the shadow layer.
There is a clearShadowLayer()
method in Paint
class, but internally that too calls the setShadowLayer
with all zero parameters. So seems like that won't work for you.
The only other way I can think of is by overriding the onDraw
method. Maintain a TextPaint
object that is set with the shadow parameters.
@Override
void setShadowLayer(.....) { // do not call super
paintWithShadowLayer.setShadowLayer(....); // the other with shadow layer set
}
@Override
void onDraw(Canvas canvas) {
super.onDraw(canvas);
...
if (bToggleON) {
canvas.drawText(text, index, count, x, y, paintWithShadowLayer);
} else {
canvas.drawText(text, index, count, x, y, getPaint());
}
...
}
Upvotes: 9