Android Custom title bar

Source: Internet
Author: User

In general development, the title of the application is configured in the Androidmanifest.xml when the application is built, or a simple string set with Settitle, if you want to add more complex layouts such as buttons, pictures, etc., use the following method

  • Function: Set title to be a string and a combination of buttons
  • Modify the Xxactivity.java code
    public void OnCreate (Bundle savedinstancestate) {
    Super.oncreate (savedinstancestate);
    Requestwindowfeature (Window.feature_custom_title); Note Order
    Setcontentview (R.layout.main); Note Order
    GetWindow (). Setfeatureint (Window.feature_custom_title,//Note order
    R.layout.title);
    }
  • Add title.xml Code
    <?xml version= "1.0" encoding= "Utf-8"?>
    <linearlayout
    Xmlns:android=http://schemas.android.com/apk/res/android
    Android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content" >
    <textview android:id= "@+id/text"
    Android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content"
    Android:layout_alignparentleft= "true"
    android:text= "Text"/>
    <button android:id= "@+id/button"
    Android:layout_width= "Wrap_content"
    android:layout_height= "30px"
    android:text= "button"/>
    </LinearLayout>



The following points need to be noted:
Note Set Order
Requestwindowfeature to Setcontentview before the
GetWindow (). Setfeatureinit Better after Setcontentview

Note Requestwindowfeature (Window.feature_custom_title) should not be used with other settings for TITLE requestwindowfeature (xxxx)

"Turn" http://bbs.androidcn.com/thread-1951-1-1.html

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.