// the layout of software activity R.layout.titlebar // TitleBar for the layout of your own title bar
set up titlebar.xml under layout:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"android:orientation= "Horizontal" > <Button Android:id= "@+id/back"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/back"android:textsize= "18SP"Android:textcolor= "#FF0000FF"/> <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/share"android:textsize= "18SP"Android:textcolor= "#FFFFFF00"/></linearlayout>
this way, although you can customize the title bar to some extent, there is no way to change the height and background of the title bar (the background setting will have two at both ends very ugly border). It is said that the reason is inherent to Android. here are the methods to modify: The principle is like this. Adding a title directly like the code above simply adds a sub-interface to the original title and does not change the original attribute. such as the title bar size, title bar background. These need to be defined in the theme theme. so first define a style, modify the background if you modify the Android:windowtitlebackgroundstyle If you change the height of the title bar, modify the Android:windowtitlesize
<?xml version= "1.0" encoding= "Utf-8"? ><resources xmlns:android= "http://schemas.android.com/apk/res/ Android "><style name=" Customwindowtitlebackground "> <item name=" Android:background "> #565656 </item></style><style name= "test" parent= "Android:theme" > <item name= "Android: Windowtitlesize ">50dp</item> <item name=" Android:windowtitlebackgroundstyle "> @style/ Customwindowtitlebackground</item></style></resources>
in the Android Manifest.xml of the program: Add properties to activity Android:theme = "@style/test" .
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.guardian"Android:versioncode= "1"Android:versionname= "1.0" > <application android:icon= "@drawable/icon" android:label= "@string/app_name" > <activity Android Oid:name= ". Guardian "Android:label= "@string/app_name"Android:theme= "@style/test"//It's right here .> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </acti vity> </application> <uses-sdk android:minsdkversion= "4"/></manifest>
You can then customize the title bar layout with the help of setting the custom title bar XML file.
originally from: Http://www.blogjava.net/Green-nut/articles/332617.html
Customizing the Android title bar TitleBar layout