Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set TextView shadow programmatically

I'm creating a TextView dynamically and set shadow to it using the method posted here: Android - shadow on text?

But it doesn't work. The style is applied (put textSize item to test, and it works), but the shadow doesn't appear.

TextView:

TextView tv = new TextView(this);
RelativeLayout.LayoutParams layoutPars = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutPars.addRule(RelativeLayout.CENTER_VERTICAL); 
tv.setTextColor(0xffffffff);
tv.setText(label);
tv.setTextSize(11);
tv.setTextAppearance(getApplicationContext(), R.style.BlackShadow);

Style:

<style name="BlackShadow">  
    <item name="android:shadowColor">#ff000000</item>
    <item name="android:shadowRadius">1</item>
    <item name="android:shadowDx">-1</item>
    <item name="android:shadowDy">-1</item>
    <item name="android:textSize">26dip</item>
</style>

What am I doing wrong?

like image 266
User Avatar asked Aug 08 '12 09:08

User


1 Answers

Try this:

tv.setShadowLayer(1.5f, -1, 1, Color.LTGRAY);

From documentation

setShadowLayer(float radius, float dx, float dy, int shadowColor)

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.

For more information please check http://developer.android.com/reference/android/graphics/Paint.html#setShadowLayer%28float,%20float,%20float,%20int%29

like image 141
Deepak Swami Avatar answered Oct 09 '22 09:10

Deepak Swami