How to set the background of the titlebar?

喜你入骨 提交于 2019-12-22 18:09:20

问题


I have followed the instructions from this SO question: How to change the text on the action bar

I am able to successfully create my own titlebar, however when I apply a background color to my layout, the color doesn't span across the entire titlebar. There are still remnants of the android gray background color.

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="400px" 
  android:layout_height="fill_parent"
  android:orientation="horizontal" android:background="@color/solid_blue">

<ImageView android:id="@+id/logo" 
            android:layout_width="57px" 
            android:layout_height="wrap_content"
            android:background="@drawable/icon">

</ImageView>

<TextView 

  android:id="@+id/myTitle" 
  android:text="StockDroid by" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:textColor="#FFFFFF"
   />
</LinearLayout>

回答1:


Remaining stuff is on that link itself as a comment man.

Edit:

The stuff you have missed to set the custom style for the Window Title and set it at the Manifest by the android:theme attribute for the activity.

you have to create this two style in your res/values/styles.xml file:

<style name="MyTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50px</item>
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground
        </item>

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

then you have to set you style as theme in you Manifest that is like:

<activity android:name=".activity"
            android:label="@string/appname" android:theme="@style/MyTheme" />

hope it helps.



来源:https://stackoverflow.com/questions/3776026/how-to-set-the-background-of-the-titlebar

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