Android user interface-action bar 5)

Source: Internet
Author: User

Set the style of the Operation bar

If you have customized the visual components in the application, you may need to re-design the operation bar to match the application design. To do this, you need to use the style attributes in the android style and theme framework to reset the style of the Operation bar.

Note: The background image that changes the appearance depends on the status of the current button (select, press, and unselect). Therefore, the resource you are using must be an approximate status list.

Warning make sure that you use the ninepatch type to draw resources for all the backgrounds that you provide to allow image stretching. Ninepatch images should be smaller than those with 40 pixels higher and 30 pixels wider.

Common appearance

Android: windowactionbaroverlay

This attribute declares whether the operation column should overwrite the activity layout, rather than the offset relative to the activity layout position. The default value of this attribute is false.

Usually, on the screen, the Operation bar requires its own space and the remaining space is used to fill the layout of the activity. When the operation column 4 overwrites the mode, the activity uses all valid spaces, and the system will describe the operation column on the activity. This overwrite mode is useful if you want to keep the layout content in a fixed size when hiding and displaying the operation bar. You may also use it only to display the effect, because you can set a translucent background for the Operation column so that you can still see the activity layout behind the operation column.

Note: by default, the holo topic uses a translucent background to describe the operation bar. However, you can use your own style to modify it. By default, the devicedefault topic may use an opaque background on different devices.

When the overwrite mode is enabled, the activity layout does not notice that the Operation column is overwritten on it. Therefore, it is best not to place some important information or UI components in the area covered by the Operation bar. If applicable, You can reference the actionbarsize value of the platform to determine the height of the Operation column. For example, you can reference this value in the XML layout file.

<Someview
...
Android: layout_margintop = "? Android: ATTR/actionbarsize "/>

You can also use the getheight () method to get the height of the Operation bar at runtime. If this method is called early in the activity lifecycle, the height of the Operation column reflected during the call may not include the stacked operation column (because of the navigation option label ). To see how to determine the overall height of the Operation column (including the stacked operation column) during running, see titlesfragment class in the honeycomb gallery example application.

Http://developer.android.com/resources/samples/HoneycombGallery/index.html

Operation item Style

Android: actionbuttonstyle

Define a style resource for the Operation item button.

Android: actionbaritembackground

Define a resource for the background of each operation item (added to API Level 14 ).

Android: itembackground

You can define traceable resources for the background of each overflow menu item.

Android: actionbardivider

Define traceable resources for separation lines between operation items (added to API Level 14)

Android: actionmenutextcolor

Define the color for the text displayed in the action item.

Android: actionmenutextappearance

Define the style resource for the text displayed in the action item.

Android: actionbarwidgetthem

Define theme resources for visual components that are filled as operation windows in the Operation bar (added to API Level 14 ).

Navigation option label Style

Android: actionbartabstyle

Define style resources for Option labels in the Operation bar.

Android: actionbartabbarstyle

Define style resources under the tab of the navigation option.

Android: actionbartabtextstyle

Define style resources for text in the navigation option label.

Drop-down list Style

Android: actiondropdownstyle

Define styles (such as background and text styles) for the drop-down navigation list ).

For example, the following XML file defines some custom styles for the Operation bar:

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<! -- The theme applied to the application or activity -->
<Style name = "customactivitytheme" parent = "@ Android: style/theme. holo">
<Item name = "Android: actionbartabtextstyle"> @ style/customtabtextstyle </item>
<Item name = "Android: actionbardivider"> @ drawable/AB _divider </item>
<Item name = "Android: actionbaritembackground"> @ drawable/AB _item_background </item>
</Style>

<! -- Style for the action bar tab text -->
<Style name = "customtabtextstyle" parent = "@ Android: style/textappearance. holo">
<Item name = "Android: textcolor"> #2456c2 </item>
</Style>
</Resources>

Note: You must declare a parent topic in the <style> label, so that the custom topic can inherit all styles that are not explicitly declared. When you modify the style of the Operation bar, it is vital to use the parent topic. It will allow you to simply overwrite the style of the Operation bar you want to change, it does not affect the style you do not want to modify (such as the appearance of the text or the edge of the Operation item ).

You can apply a custom topic to the entire application or a separate activity object in the configuration file, for example:

<Application Android: theme = "@ style/customactivitytheme".../>

Advanced Style

If you need more advanced styles than the preceding attributes, You can include the Android: actionbarstyle and Android: actionbarsplitstyle attributes in the activity topic. Each of these two attributes specifies another style that defines various attributes for the Operation bar, including different backgrounds with the Android: Background, Android: backgroundsplit, and Android: backgroundstacked attributes. If you want to overwrite these operation bar styles, make sure to define a parent operation bar style like widget. holo. actionbar.

For example, to change the background of the Operation bar, you can use the following style:

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<! -- The theme applied to the application or activity -->
<Style name = "customactivitytheme" parent = "@ Android: style/theme. holo">
<Item name = "Android: actionbarstyle"> @ style/myactionbar </item>
<! -- Other activity and action bar styles here -->
</Style>

<! -- Style for the action bar Backgrounds -->
<Style name = "myactionbar" parent = "@ Android: style/widget. holo. actionbar">
<Item name = "Android: background"> @ drawable/AB _background </item>
<Item name = "Android: backgroundstacked"> @ drawable/AB _background </item>
<Item name = "Android: backgroundsplit"> @ drawable/AB _split_background </item>
</Style>

</Resource>

 

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.