Modify title bar (title) and androidtitle for Android

Source: Internet
Author: User

Modify title bar (title) and androidtitle for Android

1. First import the ActionBarActivity package, and then inherit the MainActivity from the Activity rather than the ActionBarActivity (note that only the title of the main interface is changed here)

Import android. support. v7.app. ActionBarActivity; public class MainActivity extends Activity // otherwise, an exception occurs.

2. Add the following statement to MainActivity:

This. requestWindowFeature (Window. FEATURE_CUSTOM_TITLE); setContentView (R. layout. main); // <span style = "font-family: Arial, Helvetica, sans-serif;"> R. layout. main is 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 a title. xml layout file in layout.

<?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 attributes, create a style. xml file in the values folder, modify the title bar background and height, and set the default height to 26dip.

<?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 topic to the file whose title you want to modify

<activity            android:name=".MainActivity"            android:label="@string/app_name"           <strong>android:theme="@style/title_style"</strong>             >
6. Note that the above only changes the title of some activities, but only partial modifications. After the title bar is modified, the layout of the entire activity will change. Therefore, you must modify the corresponding layout management file. xml file



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.