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

查看:17
本文介绍了如何将样式应用于我拥有的所有 TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
设置所有 TextView(或自定义视图)的样式无需为每个 TextView 添加样式属性

我的应用中有很多 TextView .它们有各种字体大小、颜色等.我需要对它们应用 android:shadowColorandroid:shadowRadius 以使它们都带有阴影.怎么做?

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.例如,我可以为 TextViews 制作一个具有必要属性的样式

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>

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

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>

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

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" >

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

编辑

如果你只想应用到textview,那么我们只需要多自定义一下ThemeRedPlanet.

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>

我以此为例.Steve Pomeroy 更直接地应用全球主题(设置一次有点交易)

这篇关于如何将样式应用于我拥有的所有 TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆