Android: Title Bar Color don't change

社会主义新天地 提交于 2019-12-01 06:13:55

问题


I wanna change my Apps Titlebar color and tried it in this way:

Part of the manifest file:

<application
        android:icon="@drawable/icon"
        android:label="@string/app_name"  
        android:theme="@style/Theme.MyTitleBar" ></application>

The style block part of the file styles.xml:

 <style name="Theme.MyTitleBar" parent="android:Theme">
        <item name="android:colorBackground">#FFFFFF</item>
        <item name="android:background">#FFFFFF</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">16sp</item>
 </style>

But only the text color and attributes changes correct. Any guest what I did wrong?


回答1:


EDIT: I added the part for the ActionBar (sorry I put only for Dialogs at first)

You can follow this, it will allow you to change moreover other attributes that just the title bar:

Just call your custom theme in the manifest file:

 <application
    android:icon="@drawable/icon"
    android:label="@string/app_name"  
    android:theme="@style/AppTheme" >

Then create these 2 styles in your styles.xml. The first one defines the theme, the second one, one of the styles to apply on the theme:

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">     
    <item name="android:colorBackground">#FFFFFF</item>
    <item name="android:background">#FFFFFF</item>
    <item name="android:textColor">@android:color/black</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">16sp</item>
</style>

NOTE: In this example, I customize the theme Holo Light as you can see with this: android:style/Widget.Holo.Light.ActionBar.




回答2:


Add This style.xml File in your project according to your requirment...

    <item name="android:actionBarStyle">@style/myActionBar</item>

</style>



<style name="myActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">    
    <item name="android:titleTextStyle">@style/myActionBar.titleTextStyle</item>
</style>

<style name="myActionBar.titleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse">
    <item name="android:textColor">@color/darkgrey</item>
</style>

 <style name="myActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#e6ebc3</item>
</style>



来源:https://stackoverflow.com/questions/16770015/android-title-bar-color-dont-change

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