简体   繁体   English

更改Android应用的样式和主题中的文本外观

[英]Changing the text appearance in styles and themes for an Android app

I am writing an android app and I am wanting to alter the theme of my app. 我正在写一个Android应用程序,我想改变我的应用程序的主题。

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. 我已经设法通过使用主题来改变应用程序的背景颜色,但我正在努力改变默认的文本外观。

This is my styles.xml resource file. 这是我的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>

and just to check, this is an example of one of my TextViews I want to use the above style in my layout file. 并且只是为了检查,这是我的一个TextViews的例子我想在我的布局文件中使用上面的样式。

<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? 任何人都可以看到我错在哪里?

Just for completeness, and full credit to Lusprog, this is now my resources file 为了完整性,并充分信任Lusprog,现在这是我的资源文件

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

Also thanks to Padma Kumar for the font help. 还要感谢Padma Kumar提供的字体帮助。

//remove this line from your styles there is no attribute like this //从你的样式中删除这一行没有这样的属性

<item name="android:textFont">Verdana</item>

//you can give typeface for changing font style //你可以给改变字体样式的字体

<item name="android:typeface">monospace</item>

//for settting the styles //用于设置样式

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM