Possible Duplicate:
Styling all TextViews(or custom view) without adding the style attribute to every TextView
我的应用程序中有很多 TextView
。它们有各种字体大小、颜色等。我需要对它们应用 android:shadowColor
和 android:shadowRadius
以使它们都具有阴影。怎么做?
E.例如,我可以为具有必要属性的 TextView
制作样式
<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>
并将其应用于每个 TextView
。是否可以将阴影属性包含到应用程序的主题中?
是的。
你需要做的是创建一个
<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>
然后在你的 list 中你会这样做。
<application
android:debuggable="true"
android:icon="@drawable/icon"
android:label="Red Planet App"
android:theme="@style/Theme.RedPlanetTheme" >
这将允许您的整个应用程序继承您的自定义主题样式。
编辑
如果你想只应用到textview,那么我们只需要稍微定制一下ThemeRedPlanet。
<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)