Many Android programs now display buttons and titles on the title bar, such:
The following example shows how to implement it.
1. Create a titlebtn. xml file under layout with the following content:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<ImageButton
Android: id = "@ + id/imageButton1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "#00000000"
Android: layout_centerVertical = "true"
Android: layout_alignParentLeft = "true"
Android: src = "@ drawable/prv"/>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerInParent = "true"
Android: text = "title bar"/>
<ImageButton
Android: id = "@ + id/imageButton1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "#00000000"
Android: layout_centerInParent = "true"
Android: layout_alignParentRight = "true"
Android: src = "@ drawable/next"/>
</RelativeLayout>
Note the following when creating this xml:
A) Layout with RelativeLayout
B) In particular, layout_centerInParent must be specified for the properties of the right button.
2. Add the following code to onCreate in the Activity:
[Java]
RequestWindowFeature (Window. FEATURE_CUSTOM_TITLE );
SetContentView (R. layout. main );
GetWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. titlebtn );
The above two steps can be used to achieve the above effect.
From rough roads