Customize the Activity title bar of the Android mobile phone

Source: Internet
Author: User

First, let's explain in detail:

When we want to make our mobile phone full screen, we will immediately thinkRequestWindowFeature (featrueId)Function.

I. Enumeration Constants

1. DEFAULT_FEATURES: default system status, which is not required

2. FEATURE_CONTEXT_MENU: Enable ContextMenu. This option is enabled by default. Generally, you do not need to specify

3. FEATURE_CUSTOM_TITLE: Custom title. You must specify a custom title. For example, when the title is a button

4. FEATURE_INDETERMINATE_PROGRESS: uncertain progress

5. FEATURE_LEFT_ICON: icon on the left of the title bar

6. FEATURE_NO_TITLE: Wu title

7. FEATURE_OPTIONS_PANEL: enables the option panel function. It is enabled by default.

8. FEATURE_PROGRESS: Progress indicator Function

9. FEATURE_RIGHT_ICON: icon on the right of the title bar

The enumerated constants above are your reference.

Next let's take a look at the custom title.

Let's see the result diagram first.


The Code is as follows:

Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. Window;
ImpZ finished? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcnQgYW5kcm9pZC53aWRnZXQuVG9hc3Q7PGJyPgo8YnI + Signature RfRkVBVFVSRVOjus + 1zbPErMjP17TMrKOs0ruw47K70OjSqta4tqg8YnI + signature + LbIPGJyPgogICAgICAgIC Signature + signature + 7D5rDlobG5psTco6zErMjP0tHG9NPDoaM8YnI + CiAgICAgICAgICogOC5GRUFUVVJFX1BST0dSRVNTo7q9 + Signature Pipeline + pipeline = "Do you understand? ", 1). show ();
}
}

The above two lines are very important, and must appear in the Code strictly in the above sequence. That is:

RequestWindowFeature (Window. FEATURE_CUSTOM_TITLE); must appear in super. onCreate (savedInstanceState);, before setContentView (R. layout. main. This means to tell the system that the program should define its own Titlebar;

GetWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title); it must appear after setContentView, which means to tell the system that the custom layout is R. layout. title (that is, the titlebar we wrote earlier. xml)

Additional:

Main. xml


Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">


Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>




Title. xml


Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "horizontal"
>


Android: layout_width = "wrap_content"
Android: layout_height = "match_parent"
Android: textColor = "# FF0000"
Android: text = "this is my custom title"
/>

Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "add"
Android: onClick = "add"
/>

Related Article

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.