更改Android应用的样式和主题中的文本外观 [英] Changing the text appearance in styles and themes for an Android app

查看:313
本文介绍了更改Android应用的样式和主题中的文本外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Android应用程序,我想改变我的应用程序的主题。

I am writing an android app and I am wanting to alter the theme of my app.

我已经设法通过使用主题来改变应用程序的背景颜色,但我正在努力改变默认的文本外观。

I have managed to alter the background colour of the app by using a theme, but I am struggling to change the default text appearance.

这是我的 styles.xml 资源文件。

<resources>
    <style name="QTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/q_green</item>
        <item name="android:colorBackground">@color/q_green</item>
        <item name="android:textAppearance">@style/QText</item> 
    </style>

    <color name="q_green">#008000</color>
    <color name="white">#FFFFFF</color>

    <style name="QText" parent="@android:style/TextAppearance.Medium"> 
        <item name="android:textSize">20sp</item> 
        <item name="android:textColor">@color/white</item> 
        <item name="android:textStyle">bold</item>
        <item name="android:textFont">Verdana</item>
    </style>
</resources>

只是为了检查,这是我的一个 TextViews 的示例我想在我的布局文件中使用上面的样式。

and just to check, this is an example of one of my TextViews I want to use the above style in my layout file.

<TextView
    android:id="@+id/txtDevice"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/device" 
/>

谁能看到我出错的地方?

Can anyone see where I am going wrong?

推荐答案

为了完整性,并且完全归功于Lusprog,现在这是我的资源文件

Just for completeness, and full credit to Lusprog, this is now my resources file

<resources>
    <style name="QTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/q_green</item>
        <item name="android:colorBackground">@color/q_green</item>
        <item name="android:textViewStyle">@style/QText</item> 
    </style>

    <color name="q_green">#008000</color>
    <color name="white">#FFFFFF</color>

    <style name="QText" parent="@android:style/TextAppearance.Medium"> 
        <item name="android:textSize">20sp</item> 
        <item name="android:textColor">@color/white</item> 
        <item name="android:textStyle">bold</item>
        <item name="android:typeface">sans</item>
    </style>
</resources>

还要感谢Padma Kumar提供的字体帮助。

Also thanks to Padma Kumar for the font help.

这篇关于更改Android应用的样式和主题中的文本外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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