我一直在努力解決這個問題,現在我有了答案!
正如你可能已經看到了好幾個地方,你需要創建的themes.xml資源:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>
</resources>
注意它是不是經常在網站上提到談論自定義標題欄,你需要在選擇這個主題視圖,活動或應用程序級別。我這樣做是在應用層加入安卓主題屬性的應用程序:
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/MyTheme">
你還需要一個styles.xml定義WindowTitleBackgroundStyle。不像這個文件我已經看到漂浮aroung網絡的各種版本,我已經添加了一個額外的線路,設置填充爲0,其擺脫了填充的文件,你都在抱怨:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">@android:color/transparent</item>
<item name="android:padding">0px</item>
</style>
</resources>
謝謝,這對我有很大的幫助。 – 2011-11-03 18:49:39
ViewGroup上的setPadding沒有爲我做。你用0填充設置背景的建議做到了。 – AlanKley 2012-01-23 03:19:49
非常感謝,這工作完美。 – 2012-11-27 10:34:03