如何将样式应用到我拥有的所有TextViews?

Mak*_*iev 5 android themes textview

可能重复:为
所有TextView(或自定义视图)设置样式,而不将style属性添加到每个TextView

TextView我的应用程序中有很多s.它们有各种各样的字体大小,颜色等等.我需要应用它们android:shadowColorandroid:shadowRadius让它们全部带有阴影.怎么做?

例如,我可以为TextView具有必要属性的s 制作样式

<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>
Run Code Online (Sandbox Code Playgroud)

并将其应用于每个TextView.是否可以将阴影的属性包含在应用程序的主题中?

Jer*_*rad 7

是的.

你需要做的是创建一个

<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>
Run Code Online (Sandbox Code Playgroud)

然后在你的清单中你会这样做.

<application
        android:debuggable="true"
        android:icon="@drawable/icon"
        android:label="Red Planet App"
        android:theme="@style/Theme.RedPlanetTheme" >
Run Code Online (Sandbox Code Playgroud)

这将允许您的整个应用程序继承您的自定义主题样式.

编辑

如果您只想申请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>
Run Code Online (Sandbox Code Playgroud)

我用它作为例子.Steve Pomeroy更直接地应用全球主题(设置曾经有点交易)


Dip*_*iya 5

请将以下行添加到您的 textview 的属性中,它将解决您的问题。

style="@style/text_views"

  • 在这种情况下,我必须将此行添加到我拥有的每个“TextView”中。 (9认同)