5

Possible Duplicate:
Styling all TextViews(or custom view) without adding the style attribute to every TextView

I have got lots of TextViews in my app. They have various font sizes, colors, etc. I need to apply android:shadowColor and android:shadowRadius to them to have all of them with shadows. How to do it?

E. g., I can make a style for the TextViews with the necessary properties

<style name="text_views">
    <item name="android:shadowColor">@color/tv_shadow</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.7</item>
</style>

and apply it to each TextView. Is it possible to include properties for the shadows to theme of the application?

Community
  • 1
  • 1
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138

2 Answers2

8

Yes it is.

What you need to do is create an

<style name="Theme.RedPlanetTheme" parent="android:Theme">
    <item name="android:shadowColor">@color/tv_shadow</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.7</item>
</style>

Then in your manifest you would do this.

<application
        android:debuggable="true"
        android:icon="@drawable/icon"
        android:label="Red Planet App"
        android:theme="@style/Theme.RedPlanetTheme" >

This will allow your whole application to inherit your custom theme style.

Edit

If you want to apply to only textview, then we just need to customize the ThemeRedPlanet a bit more.

<style name="Theme.RedPlanetTheme" parent="android:Theme">    
    <item name="android:textAppearance">@style/MyRedTextAppearance</item>
</style>

<style name="MyRedTextAppearance" parent="@android:style/TextAppearance">
    <item name="android:shadowColor">@color/tv_shadow</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.7</item>
</style>

I'm using this as example. Steve Pomeroy applys more directly globally themed (set once kinda deal)

Community
  • 1
  • 1
Jerad
  • 709
  • 5
  • 11
  • Ah yes, You will need to then make some minor modifcation to your Theme.RedPlanetTheme so the style will be used on TextViews only. I will modify my answer – Jerad Nov 28 '12 at 07:23
5

Please add below line into your textview's property, it will solve your problem.

style="@style/text_views"

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128