android - 如何将样式应用于我拥有的所有 TextView?

标签 android textview themes

<分区>

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

我的应用程序中有很多 TextView。它们有各种字体大小、颜色等。我需要对它们应用 android:shadowColorandroid: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)

关于android - 如何将样式应用于我拥有的所有 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13599553/

相关文章:

android - 如何在一行 TextView 的左右两侧对齐文本?

javascript - Wordpress 3.8.3 自定义主题

android - 智能 : Getting GridLayout work

带有 onclickListener 的 Android 页脚

java - 使用后端服务器的谷歌身份验证需要范围

templates - 在哪里可以找到一些好的 UI 模板来设计我的应用程序?

themes - 如何更改主题以将背景颜色设置为 TextMate 2 中的当前行?

c# - Xamarin Resource.Id 无法识别

android - 在 TextView 中选择文本并长按时调用 float 菜单

android - 以编程方式将 TextView 添加到 XML 布局