Any way to set the text shadow for a SpannableString?
I've got an Android home screen widget, with a TextView
on it.. Unfortunately, I'm having some issues styling it..
I want to apply a dynamic (changing from code) shadow to the text, and I'm not sure how to do this. I can set the shadow in the layout, but if I want to change it in code, there's no way to do this over a RemoteView
!
I thought I could do this with a SpannableString
, but I can't find anything useful.. If I use a TextAppearanceSpan
in it, it will ignore the shadow attributes from the style. Furthermore, the 开发者_开发百科moment I start using a SpannableString
on a TextView
it starts ignoring the shadow that I applies to the TextView
:(
What's wrong with that, and what's my best course of action here?
Edited: this won't work on widgets since custom views cannot be used there. But it might be of some help for someone trying to set it on a remote view somewhere else.
See http://code.google.com/p/android/issues/detail?id=10029
A way of doing this would be to make a custom TextView called ShadowyTextView, with a method for each value I want to set.
Then is just a matter of writing something like:
remoteViews.setInt(R.id.myShadowyText, "setShadowColor", someColor);
And so the attribute is set by reflection.
Maybe not the most elegant solution, but couldn't found anything better.
Try with the following code
TextView textHello = (TextView)findViewById(R.id.hello);
textHello.setShadowLayer(
5f, //float radius
10f, //float dx
10f, //float dy
0xFFffffff //int color
);
精彩评论