Grendizer Grendizer - 1 year ago 55
Android Question

Android - shadow on text?

I am wondering how to add shadow on text in android?

I have the following code which is applied on a bitmap and I wanted to be shadowed...

paint.setShadowLayer(1, 0, 0, Color.BLACK); //This only shadows my whole view...

Thankful for any tips!

Answer Source

You should be able to add the style, like this (taken from source code for Ringdroid):

  <style name="AudioFileInfoOverlayText">
    <item name="android:paddingLeft">4px</item>
    <item name="android:paddingBottom">4px</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:textSize">12sp</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">1</item>

And in your layout, use the style like this:

 <TextView android:id="@+id/info"
       android:gravity="center" />

Edit: the source code can be viewed here:

Edit2: To set this style programmatically, you'd do something like this (modified from this example to match ringdroid's resources from above)

TextView infoTextView = (TextView) findViewById(;

The signature for setTextAppearance is

public void setTextAppearance (Context context, int resid)

Since: API Level 1
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.