1, first import the Actionbaractivity package, and then inherit the mainactivity activity instead of actionbaractivity (note that this changes only the title of the main interface)
Import Android.support.v7.app.actionbaractivity;public class Mainactivity extends Activity//Otherwise an exception will occur
2. Add the following statement in Mainactivity
This.requestwindowfeature (Window.feature_custom_title); Setcontentview (r.layout.main);//<span style= " Font-family:arial, Helvetica, Sans-serif; >r.layout.main for your layout file </span>this.getwindow (). Setfeatureint (Window.feature_custom_title,r.layout.title );//<span style= "font-family:arial, Helvetica, Sans-serif;" >r.layout.title the layout file after you delete the title </span>
3. Create title.xml layout files in layouts
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" horizontal " android:layout_width=" fill_parent " android:layout_height = "Wrap_content" > <textview android:id= "@+id/tbartxt" android:layout_width= "Fill_parent " android:layout_height= "Fill_parent" android:text= "@string/app_name" android:textsize= "19DP " Android:textcolor= "#ffffff" android:gravity= "center" > </TextView></LinearLayout>
4, modify the Title property, in the values folder to establish the Style.xml file, modify the title bar background and height, the default height of 26dip, you can modify
<?xml version= "1.0" encoding= "Utf-8"? ><resources><style name= "Customwindowtitlebackground" >< Item Name= "Android:background" > #09adeb </item></style> <style name= "Title_style" parent= " Android:theme "> <item name=" android:windowtitlesize ">26dip</item> <item name=" Android: Windowtitlebackgroundstyle "> @style/customwindowtitlebackground</item></style></resources>
5. Add a theme to the file you want to change the title to
<activity android:name= ". Mainactivity " android:label=" @string/app_name " <strong>android:theme=" @style/title_style "</ Strong> >
6, note that the above just changed the title of part of the activity, only the local modification, after modifying the title bar, the entire activity layout will change, so you must modify the corresponding layout management file. xml file
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android modified title bar (title)