Android 自定義標(biāo)題欄背景
設(shè)置標(biāo)題欄背景
1> 準(zhǔn)備背景圖片: background_pix.png

注:用背景圖片比用顏色好處,可以讓背景看起來有凹凸感.
2> drawable文件夾下放xml文件
bitmap_repeat.xml
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/title_pic" android:tileMode="repeat"> </bitmap>
3> 定義樣式文件style.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 自定義標(biāo)題樣式 --> <style name="StatusBarBackground"> <item name="android:background">@drawable/bitmap_repeat </item> </style> <style name="XTheme" parent="android:Theme"> <!-- Window attributes --> <item name="android:windowTitleBackgroundStyle">@style/StatusBarBackground </item> </style> <!-- 自定義標(biāo)題樣式 --> </resources>
4> 在manifest.xml中引用主題android:theme="@style/XTheme"
<activity android:name=".activity.MainActivty" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" android:theme="@style/XTheme"> </activity>
自定義標(biāo)題欄layout文件ct_title.xml
注: ct_title.xml文件中用如下方式設(shè)置標(biāo)題欄背景會出下填充不滿效果
android:background="@drawable/bitmap_repeat "
在activity中引用
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.ct_title);
}

相關(guān)文章
Android開發(fā)筆記 今天學(xué)到的一些屬性
離開實驗室之前再貼上今天下午自己學(xué)到的一些基礎(chǔ)知識 上午干嘛了呢,忙著數(shù)據(jù)恢復(fù)呢2012-11-11
flutter InheritedWidget使用方法總結(jié)
這篇文章主要為大家介紹了flutter InheritedWidget使用方法總結(jié)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Android組件之DrawerLayout實現(xiàn)抽屜菜單
DrawerLayout組件同樣是V4包中的組件,也是直接繼承于ViewGroup類,所以這個類也是一個容器類。接下來通過本文給大家介紹Android組件之DrawerLayout實現(xiàn)抽屜菜單,感興趣的朋友一起學(xué)習(xí)吧2016-02-02
Android Framework Application Framework層簡單介紹
這篇文章主要介紹了 Android Framework Application Framework層簡單介紹的相關(guān)資料,需要的朋友可以參考下2016-11-11

