Android Custom title bar, filled 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" ?> <  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 styles -<stylename= "Statusbarbackground"><Itemname= "Android:background">@drawable/bitmap_repeat</Item></style><stylename= "Xtheme"Parent= "Android:theme"><!--Window Attributes -<Itemname= "Android:windowtitlebackgroundstyle">@style/statusbarbackground</Item></style><!--Custom Heading styles -</Resources>

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

<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
@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);}

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

For details, see: http://www.iteye.com/topic/760314

Code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
Second.zip

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.