Change both text and background color in title bar (Android)?

心不动则不痛 提交于 2019-12-23 12:53:49

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/18624091/change-both-text-and-background-color-in-title-bar-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!