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.