Android Learning Note: Android activity bar

Source: Internet
Author: User

After Android3.0 ,Google has made a series of changes to UI navigation design, and one of the most useful new features is the introduction of ActionBar , used to replace 3.0 the previous title bar, and provides a richer navigation effect.

ActionBar is able to display the app icon and activity title, as well as the action Item activity item.

main uses of ActionBar:

1. Ability to set the icon and title of the Activity.

2. Can be used with fragment or drop-down list to achieve the navigation of different pages.

3. Ability to join action View to provide quick access to users.

Enable ActionBar:

(1). above Android3.0 The version number is enabled by default ActionBar the. We will find that the new Activity is inherited from Actionbaractivity by default .

Suppose you want to close ActionBar, we can set the theme to Xxx.noactionbar. Like the following:

<activity android:theme= "@android: Style/theme.holo.noactionbar" >

(2). we can also be able to call in code Show () or Hide () method to display or hide the corresponding ActionBar

. before we use actionbar.hide () method is used. By default , the space occupied by ActionBar is assigned to the interface, and the displayed interface will be drawn again. Same call actionbar.show (); will also draw the interface again.

Suppose we have a program that needs to show or hide ActionBar frequently so that it doesn't have a good effect.

Google provided to a property that allows ActionBar float on the interface and of course you can make ActionBar the background is transparent. This will result in a good experience.

(3). Display the Options menu on the active bar

This is to solve the problem that many phones no longer offer a Menubutton.

MenuItem provides the setshowasaction (int actionenum) method to display menu items on ActionBar as Action Item .

Actionenum optional parameters such as the following:

Show_as_action_always: The MenuItem is always displayed on ActionBar .

Show_as_action_collapse_action_view: Collapses the ACTION VIEW into a regular menu item

Show_as_action_if_room: The MenuItem is displayed if the ActionBar position is sufficient .

Show_as_action_never: Not displayed on ActionBar

Show_as_action_with_text: Displays only the text of the MenuItem on ActionBar .

Of course we can also change the menu item's XML file to display it on the ActionBar , only need to change <item.../> the android:showasaction property.

Android has different ways of handling different devices when the ActionBar space on the top of the phone is not enough . There is a menu button that shows the menus that cannot be displayed on menus that are fired by the menu button and the phone without the menu key will ActionBar The last display is a collapsed icon. Clicking the icon will cause the remaining menu items to appear.

(4). turn the app icon on the activity bar into a clickable icon.

The ability to invoke these methods such as the following:

Setdisplayhomeasupenabled (Boolean Showhomeasup): sets the app icon to be able to click and add a left arrow to the icon, usually for fallback to parent Activity .

setdisplayoptions (int options): controls The display options for ActionBar.

Setdisplayshowhomeenable (Boolean showhome): Sets whether the application icon is displayed.

Sethomebuttonenabled (Boolean enabled): sets whether to turn the application icon into a button that can be clicked.

When you click this icon. The system will invoke Activity with android. the onoptionsitemselected () method of the R.id.home ID .

In order to respond to click events, we also need to add the corresponding processing to the onoptionsitemselected method in the Options menu .

(5). Show on the activity bar Action View

We are able to add common components to the active bar in the following two ways, for example.

1. When you define an action Item , use the android:actionviewclass property to specify the action View implementation class.

2 When you define an action Item , use the android:actionlayout property to specify the action View implementation class.

(6). Use ActionBar Implement Tab Navigation

To display multiple tab tabs on ActionBar, clicking the tab tab navigates to the specified tab Page.

The process of implementing the Tab navigation is as follows:

1. set the mode for ActionBar to Tab navigation Setnavigationmode (actionbar.navigation_mode_tabs ). This method is also able to set the number of parameters actionbar.navigation_mode_list. That is used to implement the drop-down list.

2. Call ActionBar 's addTab () method to add multiple tab tabs to the active bar . and Add event listeners for each tab tag.

For better presentation of the Tab navigation effect. We often use ActionBar and Fragment together.

Fragment can create multiple pages in one Activity . Detailed usage methods are described later.

(7). except Tab navigating outside. We can also use ActionBar to implement pull-down navigation. Detailed procedures such as the following:

1.ActionBar Sets the mode to drop-down list setnavigationmode (actionbar.navigation_mode_list).

2. Call the setlistnavigationcallbacks (Spinneradapter Adapter,actionbar.onnavigationlistener callback) method, An event listener that joins multiple list items and list items for the drop-down list.


Android Learning Note: Android activity bar

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.