omega
omega

Reputation: 43953

Android text shadow not working

In my android app, I dynamically make a text view and assign it this style:

<style name="keys">
    <item name="android:textSize">25sp</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">0.0</item>
    <item name="android:shadowDy">0.0</item>
    <item name="android:shadowRadius">2.0</item>
</style>

All the properties works except the shadow... I'm also not talking about the eclipse preview. I mean it doesn't work when I run it on the phone (physical).

Does anyone know whats wrong?

Thanks

Upvotes: 1

Views: 1918

Answers (1)

Kevin Coppock
Kevin Coppock

Reputation: 134714

Separate out the text attributes from the layout attributes, and apply them with the textAppearance attribute. That is, instead of:

<style name="keys">
    <item name="android:textSize">25sp</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">0.0</item>
    <item name="android:shadowDy">0.0</item>
    <item name="android:shadowRadius">2.0</item>
</style>

You would have:

<style name="Keys">
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
</style>

<style name="KeysAppearance">
    <item name="android:textSize">25sp</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">0.0</item>
    <item name="android:shadowDy">0.0</item>
    <item name="android:shadowRadius">2.0</item>
</style>

and in your layout, instead of:

<TextView
    style="@style/keys"/>

You would have:

<TextView
    style="@style/Keys"
    android:textAppearance="@style/KeysAppearance" />

Upvotes: 2

Related Questions