Android--Customize title bar, fill with background color

Source: Internet
Author: User

    • Set the title bar background

1> Preparation Background Image: background_pix.png

Note: Using a background image is better than using color to make the background look like a bump.

2> drawable folder XML file

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> Defining style Files Style.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources><!--custom heading 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><!--custom heading style--></ Resources>

4> references the theme android:theme="@style/xtheme" in Manifest.xml

<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: The Ct_title.xml file has the following way to set the title bar background will be out of fill dissatisfaction effect

android:background= "@drawable/bitmap_repeat"
    • Referencing in activity
@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);}

Reprint Please specify source: http://www.cnblogs.com/yydcdut/p/3694597.html

Android--Customize title bar, fill with background color

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.