可能重复: 对所有TextView(或自定义视图)进行样式设置,而无需向每个TextView添加样式属性
我的应用程序中有很多TextView 。 他们有各种字体大小,颜色等。我需要将android:shadowColor和android:shadowRadius应用于它们,以使它们都具有阴影。 怎么做?
例如,我可以使用必要的属性为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 。 是否可以将阴影的属性包含到应用程序的主题中?
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?
最满意答案
是的。
你需要做的是创建一个
<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>然后在你的清单中你会这样做。
<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>我以此为例。 史蒂夫波梅罗更直接地应用全球主题(设置一次有点儿交易)
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)
更多推荐
发布评论