如何将样式应用于我拥有的所有TextView?(How to a apply style to all the TextViews I have? [duplicate])

编程入门 行业动态 更新时间:2024-10-27 11:21:02
如何将样式应用于我拥有的所有TextView?(How to a apply style to all the TextViews I have? [duplicate])

可能重复: 对所有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)

更多推荐

本文发布于:2023-07-16 03:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用于   如何将   样式   TextView   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!