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 ).