更改文字和背景颜色标题栏(Android版)? [英] Change both text and background color in title bar (Android)?

查看:195
本文介绍了更改文字和背景颜色标题栏(Android版)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Android应用程序,我试图改变标题的酒吧背景和文本颜色。

在AndroidManifest.xml中:

 <应用
    ...
    机器人:主题=@风格/ ThemeSelector
>

在styles.xml:

 <样式名称=ThemeSelector父=机器人:Theme.Light>
    <项目名称=机器人:windowTitleBackgroundStyle> @风格/ WindowTitleBackground< /项目>
< /风格><样式名称=WindowTitleBackground>
    <项目名称=机器人:背景> @彩色/ titlebackgroundcolor< /项目>
    <项目名称=机器人:文字颜色> @彩色/ titletextcolor< /项目>
< /风格>

使用这个code,我设法改变背​​景颜色,但不是文本颜色。

可以解释为什么这code不起作用?

感谢您


解决方案

 <样式名称=ThemeSelector父=机器人:Theme.Light>
    <项目名称=机器人:windowTitleBackgroundStyle> @风格/ WindowTitleBackground< /项目>
    <项目名称=机器人:windowTitleStyle> @风格/ CustomWindowTitle< /项目>
< /风格><样式名称=WindowTitleBackground>
    <项目名称=机器人:背景> @彩色/ titlebackgroundcolor< /项目>
< /风格><样式名称=CustomWindowTitle父=WINDOWTITLE>
    <项目名称=机器人:textAppearance> @风格/ CustomWindowTitleText< /项目>
< /风格><样式名称=CustomWindowTitleText父=机器人:TextAppearance>
    <项目名称=机器人:文字颜色> @彩色/ titletextcolor< /项目>
< /风格><样式名称=WINDOWTITLE>
    <项目名称=机器人:单线>真< /项目>
    <项目名称=机器人:textAppearance> @风格/ CustomWindowTitleText< /项目>
    <项目名称=安卓则shadowColor>#BB000000< /项目>
    <项目名称=机器人:shadowRadius> 2.75 LT; /项目>
< /风格>

I build an Android app and I am trying to change the title's bar background and text colour.

In AndroidManifest.xml:

<application
    ...
    android:theme="@style/ThemeSelector"
>

In styles.xml:

<style name="ThemeSelector" parent="android:Theme.Light">
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>

<style name="WindowTitleBackground">     
    <item name="android:background">@color/titlebackgroundcolor</item>
    <item name="android:textColor">@color/titletextcolor</item>
</style>

Using this code, I am managing to change the background colour but not the text colour.

Can you explain why this code does not work?

Thank you

解决方案

<style name="ThemeSelector" parent="android:Theme.Light">
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    <item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
</style>

<style name="WindowTitleBackground">     
    <item name="android:background">@color/titlebackgroundcolor</item>
</style>

<style name="CustomWindowTitle" parent="WindowTitle">
    <item name="android:textAppearance">@style/CustomWindowTitleText</item>
</style>

<style name="CustomWindowTitleText" parent="android:TextAppearance">
    <item name="android:textColor">@color/titletextcolor</item>
</style>

<style name="WindowTitle">
    <item name="android:singleLine">true</item>
    <item name="android:textAppearance">@style/CustomWindowTitleText</item>
    <item name="android:shadowColor">#BB000000</item>
    <item name="android:shadowRadius">2.75</item>
</style>

这篇关于更改文字和背景颜色标题栏(Android版)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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