Android official getting started documentation [7] style-based operation bar

Source: Internet
Author: User

Android official getting started documentation [7] style-based operation bar
Android official getting started documentation [7] Styling the Action Bar
Style operation bar

 

This lesson teaches you
1. Use an Android Theme
2. Customize the Background
3. Customize the Text Color
4. Customize the Tab Indicator

You shoshould also read
• Styles and Themes
• Android Action Bar Style Generator

This lesson teaches you
1. Use Android themes
2. Custom background
3. Custom text color
4. Custom tab indicator

You should also read
• Style and topic
• Android operation bar style Generator

The action bar provides your users a familiar and predictable way to perform actions and navigate your app, but that doesn't mean it needs to look exactly the same as it does in other apps. if you want to style the action bar to better fit your product brand, you can easily do so using Android's style and theme resources.
The operation Bar provides a familiar and predictable way to operate and browse your application. However, this does not mean that it must look exactly like it in other applications. If you want to style the operation bar to better meet your product trademark, you can easily use Android style and theme resources.

Android uplodes a few built-in activity themes that include dark or light action bar styles. You can also extend these themes to further customize the look for your action bar.
Android includes some built-in activity themes, including "dark" or "light" style of the Operation bar. You can also extend the appearance of these themes to your operation bar.

Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme. appCompat family of styles (rather than the Theme. holo family, available in API level 11 and higher ). in doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties encoded in the Support Library (the appcompat. r. attr properties-the context for these properties is actually your app ). see the examples below for details.
Note: If you are using the API operation column of the supported library, you must use (or override) Theme. appCompat family style (not Theme. holo family, providing API level 11 or higher ). In this way, each style attribute must be declared twice: the platform's style attribute (Android: attribute) is used at a time. Once the style attribute is included in the support library (the appcompat. r. attr properties-the context of these features is actually your application ). For more information, see the example below.

 

Use an Android Theme
Use Android themes


--------------------------------------------------------------------------------


Android uplodes two baseline activity themes that dictate the color for the action bar:
• Theme. Holo for a dark theme.
• Theme. Holo. Light for a light theme.
Android includes two basic activity themes, which determine the color of the Operation bar:
• Theme. Holo: A dark drak topic.
• Theme. Holo. Light is a "light" topic.

 

You can apply these themes to your entire app or to individual activities by declaring them in your manifest file with the android: theme attribute for the element or individual elements.
You can apply to your entire application or individual activities by declaring them in your manifest list file and the android: theme attribute for the element or independent element.

For example:
For example:

You can also use a dark action bar while the rest of the activity uses the light color scheme by declaring the Theme. Holo. Light. DarkActionBar theme.
You can also use the dark operation bar, while the rest of the activity uses the color scheme of Light by declaring Theme. Holo. Light. DarkActionBar themes.

When using the Support Library, you must instead use the Theme. AppCompat themes:
• Theme. AppCompat for the dark theme.
• Theme. AppCompat. Light for the light theme.
• Theme. AppCompat. Light. DarkActionBar for the light theme with a dark action bar.
When using the supported libraries, you must use Theme. AppCompat topic instead:
• Theme. AppCompat is the Theme of "dark.
• Theme. AppCompat. Light is the subject of "light.
• Theme. AppCompat. Light. DarkActionBar is the light and dark operation bar of the topic.

Be sure that you use action bar icons that properly contrast with the color of your action bar. to help you, the Action Bar Icon Pack includes des standard action icons for use with both the Holo light and Holo dark action bar.
Make sure that you use the operation bar icon, which is properly compared with the color of your operation bar. To help you use the standard action icon in both the Holo light and Dark drak actions bar.

 

Customize the Background
Custom background

--------------------------------------------------------------------------------


To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. this property points to another style in which you can override the background property to specify a drawable resource for the action bar background.
To change the background of the Operation bar, create a custom topic for your activity and overwrite the actionBarStyle attribute. This property points to another style. You can override the background property to specify the resource to be drawn in the Action Bar background.

 

If your app uses navigation tabs or the split action bar, then you can also specify the background for these bars using the backgroundStacked and backgroundSplit properties, respectively.
If your application uses the navigation tab or the split operation bar, you can also specify the background bars to use the backgroundStacked and backgroundSplit attributes, respectively.

Caution: It's important that you declare an appropriate parent theme from which your custom theme and style inherit their styles. without a parent style, your action bar will be without character style properties unless you explicitly declare them yourself.
Note: This is an appropriate parent topic you declare. It is important to inherit from your custom themes and styles. If you do not have a parent style, your operation bar will not have many style attributes unless you explicitly declare them.

For Android 3.0 and higher only
For Android3.0 and later versions

 

When supporting Android 3.0 and higher only, you can define the action bar's background like this:
When Android 3.0 and later versions are supported, you can define the background of the Operation column as follows:

Res/values/themes. xml


{C}

{C}


Then apply your theme to your entire app or individual activities:
Then your topic is applied to the entire application or personal activity:

 

For Android 2.1 and higher
For Android2.1 and higher

 

When using the Support Library, the same theme as above must instead look like this:
When the support library is used, the same theme as above must be:

Res/values/themes. xml


{C}

{C}


Then apply your theme to your entire app or individual activities:
Then your topic is applied to the entire application or personal activity:

 

Customize the Text Color
Custom text color


--------------------------------------------------------------------------------

To modify the color of text in the action bar, you need to override separate properties for each text element:
To modify the text color in the Operation column, you need to override the individual attributes of each text element:

• Action bar title: Create a custom style that specifies the textColor property and specify that style for the titleTextStyle property in your custom actionBarStyle.
• Operation bar title: create a custom style, specify the textColor attribute, and specify the titleTextStyle attribute of the custom actionBarStyle.

Note: The custom style applied to titleTextStyle shocould use TextAppearance. Holo. Widget. ActionBar. Title as the parent style.
Note: TextAppearance. Holo. Widget. ActionBar. Title should be used for the custom style of titleTextStyle.

• Action bar tabs: Override actionBarTabTextStyle in your activity theme.
• Operation tab: overwrite actionBarTabTextStyle in the activity topic.

• Action buttons: Override actionMenuTextColor in your activity theme.
• Action button: override actionMenuTextColor in your activity topic.

 

For Android 3.0 and higher only
For Android3.0 and later versions

 

When supporting Android 3.0 and higher only, your style XML file might look like this:
When Android 3.0 and later versions are supported, your style XML file may be like this:

Res/values/themes. xml


{C}

{C}

{C}

{C}


 

For Android 2.1 and higher
For Android2.1 and higher

 

When using the Support Library, your style XML file might look like this:
When using the support library, your style XML file may be like this:

Res/values/themes. xml


{C}

{C}

{C}

{C}


 

Customize the Tab Indicator
Custom tab indicator


--------------------------------------------------------------------------------

 

To change the indicator used for the navigation tabs, create an activity theme that overrides the actionBarTabStyle property. this property points to another style resource in which you override the background property that shoshould specify a state-list drawable.
To change the instructions for the navigation label, create an activity topic that overwrites the actionBarTabStyle attribute. This attribute points to a resource that overwrites a list of States that should be specified to draw a background attribute and another style.

Note: A state-list drawable is important so that the tab currently selected indicates its state with a background different than the other tabs. for more information about how to create a drawable resource that handles multiple button states, read the State List documentation.
Note: It is very important to draw the status list, so that the selected tab shows the status of different backgrounds than other labels. For more information about how to create a resource that can process the status of multiple buttons, see the status list file.

For example, here's a state-list drawable that declares a specific background image for several different states of an action bar tab:
For example, there is a status list to draw several different background images that declare an operation bar tab:

Res/drawable/actionbar_tab_indicator.xml


Android: state_pressed = false
Android: drawable = @ drawable/tab_unselected/>
Android: state_pressed = false
Android: drawable = @ drawable/tab_selected/>


Android: state_pressed = false
Android: drawable = @ drawable/tab_unselected_focused/>
Android: state_pressed = false
Android: drawable = @ drawable/tab_selected_focused/>



Android: state_pressed = true
Android: drawable = @ drawable/tab_unselected_pressed/>
Android: state_pressed = true
Android: drawable = @ drawable/tab_selected_pressed/>


Android: state_pressed = true
Android: drawable = @ drawable/tab_unselected_pressed/>
Android: state_pressed = true
Android: drawable = @ drawable/tab_selected_pressed/>


 

For Android 3.0 and higher only
For Android3.0 and later versions

 

When supporting Android 3.0 and higher only, your style XML file might look like this:
When Android 3.0 and later versions are supported, your style XML file may be like this:

Res/values/themes. xml





 

For Android 3.0 and higher only
For Android3.0 and later versions

 

When supporting Android 3.0 and higher only, your style XML file might look like this:
When Android 3.0 and later versions are supported, your style XML file may be like this:

Res/values/themes. xml





 

For Android 2.1 and higher
For Android2.1 and higher

 

When using the Support Library, your style XML file might look like this:
When using the support library, your style XML file may be like this:

Res/values/themes. xml





More resources
• See more style properties for the action bar are listed in the Action Bar guide.
• Learn more about how themes work in the Styles and Themes guide.
• For even more complete styling for the action bar, try the Android Action Bar Style Generator.
More resources
• See Guide more style attributes in the Operation column.
• Understanding

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.