Android modified title bar (title)

Source: Internet
Author: User

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)

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.