1

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

omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

2

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" />
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • You can't set a style at runtime. You'll have to apply these attributes manually on the `TextView` (e.g. `myTextView.setShadowColor()`). Alternately, make a layout containing just the `TextView` with the styles set, and inflate it at runtime. – Kevin Coppock Jun 05 '14 at 00:57