Android changes the layout of the window title bar

Source: Internet
Author: User

 

I. Key Points
Generally, the title of an application is created in androidmanifest. if you want to add buttons, images, and other complex la S, you can use the following methods:
When creating a window, you can set an XML layout to the title of the application.

 

Ii. Instances

A) function: Set the title to a combination of a string and a button.

B) modify the xxactivity. Java code
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Requestwindowfeature (window. feature_custom_title); // pay attention to the sequence
Setcontentview (R. layout. Main); // pay attention to the sequence
Getwindow (). setfeatureint (window. feature_custom_title, // pay attention to the sequence
R. layout. Title );
}

C) add the 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>

3. Note

A) Pay attention to setting the sequence.
Requestwindowfeature must be before setcontentview
Getwindow (). setfeatureinit is better after setcontentview

B) Note that the requestwindowfeature (window. feature_custom_title) should not be used together with other settings for the title requestwindowfeature (XXXX ).

 

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.