Android and android Official Website
- Set the title bar background
1> prepare a background image:Background_pix.png
Note: it is better to use a background image than a color image to make the background look blurred.
2> place xml files in the drawable folder
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> define the style File style. xml
<? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <! -- Customize the title style --> <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> <! -- Customize the title style --> </resources>
4> reference the topic android: theme = in manifest. xml"@ Style/XTheme"
<activity android:name=".activity.MainActivty"android:screenOrientation="portrait"android:configChanges="keyboardHidden|orientation"android:theme="@style/XTheme"></activity>
- Custom title bar layout file ct_title.xml
Note: In the ct_title.xml file, setting the title bar background in the following way will result in insufficient filling.
android:background="@drawable/bitmap_repeat "
@Overridepublic 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);}
Reprinted please indicate the source: http://www.cnblogs.com/yydcdut/p/3694597.html