Android user interface-action bar 2)

Source: Internet
Author: User
Tags xml attribute

Select Operation items

By evaluating some key features, you should carefully select the menu items in the option menu to be displayed as operation items. Generally, each operation item should satisfy at least one of the following features:

1. Frequent use: operations required for more than 70% of user visits, or operations to be used repeatedly.

2. important: it is an operation that users can easily find. Even if it is not a regular operation, users need to easily find and execute it as needed.

For example, add a network in Wi-Fi settings.

3. Typical: it is a typical operation provided in the Operation bar of an application. Therefore, users expect to find it in the Operation bar.

For example, "refresh" in an email or social app.

If you want to adjust more than four menu items to operation items, you should carefully consider their relative importance level, and try setting up to four or more operation items (and use the "ifroom" attribute value to allow the system to encounter a small screen with limited space, can put the back operation items in the overflow menu ). Even on some wide-screen devices, you should not create many operations to disrupt the UI layout and be more like a desktop toolbar, therefore, we need to keep the minimum number of operation items.

In addition, the following operations should never be displayed as operation items: settings, help, feedback, or similar operations. Keep them in the overflow menu.

Note: not all devices provide dedicated hardware buttons for retrieval. Therefore, if it is an important feature in your application, it should always be displayed as an operation item (and usually placed in the first position, especially when the operation is provided in the Operation window ).

Use split operation bar

When your application is running on Android (API Level 14) or later, an additional mode called "split operation bar" is also effective for the Operation column. When you enable the split operation bar mode, an independent horizontal bar is displayed at the bottom of the screen to display all the operation items that the activity runs on a narrow screen device (such as a vertical screen mobile phone.

Separate the operation columns into independent operation items to ensure that there is a suitable space on the narrow screen device to display all the operation items, while leaving the navigation bar and the title element at the top.

To enable the split operation bar, simply add the uioptions = "splitactionbarwhennarrow" attribute to the <Application> or <activity> element.

Note that android will adjust the appearance of the Operation bar in various ways based on the current screen size. Using the split operation bar is only one of the options you can enable to allow the operation bar to further optimize user experience for different screen sizes. You can also allow the operation bar to fold the navigation option label to the main operation bar. If you use the navigation option label in the Operation bar, once the operation item is separated on the narrow screen device, these navigation option labels may be filled in the main operation bar, instead of being separated to the stacked operation bar. In particular, If you disable the icons and titles in the Operation column (using the setdisplayshowhomeenabled (false) and setdisplayshowtitleenabled (false) methods), the navigation option label is folded into the main operation column, for example, 3 shows the second device:

Figure 3. The left side is the split operation column with the navigation option label, and the right side is the split operation column with the application icon and title disabled.

Note: although the Android: uioptions attribute is added only in android4.0 (API Level 14), to maintain compatibility with low Android versions, even if your minsdkversion attribute value is less than 14, your application can also safely include the Android: uioptions attribute. When running on an earlier version, the XML Attribute is ignored because the system cannot understand this attribute. The only condition that your configuration file contains this attribute is that you must compile your application on a platform that supports API Level 14 or later. To maintain compatibility, you cannot use APIs that are not supported by the version declared by the minsdkversion attribute in your application code. Only the XML Attribute can be safely ignored by the old platform version.

Use the application icon to navigate

By default, the application icon is displayed on the left of the Operation bar. You can use this icon as an operation item. The application should respond to one of the following two operations on this icon:

1. Return the "Main" activity of the application;

2. navigate to the application superior page.

When you touch this icon, the system will call the onoptionsitemselected () method with Android. R. Id. Home ID in the activity. In this response, you can either start the main activity or return the user's previous operation interface in the structural hierarchy of your application.

If you want to return the primary activity through the response of the application icon, you should include the flag_activity_clear_top identifier in the itent object. With this tag, if the activity you want to start already exists in the current task, all the activities on this activity in the stack will be destroyed, and display the activity to the user. It is often important to add this identifier. Because the returned primary activity is equivalent to a rollback action, you should not create another primary activity instance. Otherwise, in the end, a long stack with multiple active activities may be generated in the current task.

For example, the onoptionsitemselected () method in the following example implements the operation to return the main activity of the application:

@ Override
Public Boolean onoptionsitemselected (menuitem item ){
Switch (item. getitemid ()){
Case Android. R. Id. Home:
// App icon in action bar clicked; go home
Intent intent = new intent (this, homeactivity. Class );
Intent. addflags (intent. flag_activity_clear_top );
Startactivity (intent );
Return true;
Default:
Return super. onoptionsitemselected (item );
}
}

When a user enters the current activity from another application, you may want to add the flag_activity_new_task identifier. This identifier ensures that the new activity will not be added to the current task when the user returns to the homepage or upper-level page, but will be started in the task of your own application. For example, if a user starts an activity in your application by using an intent object called by another application, when you select the action bar icon to return to the homepage or upper-level page, the flag_activity_clear_top flag starts the activity (not the current task) in the task of your application ). The system can use this new activity as the root activity to start a new task, or bring a existing task with the activity instance in the background to the foreground, and the target activity will accept the onnewintent () callback. Therefore, if your activity needs to receive the intent object of another application, you should add the flag_activity_new_task identifier to the intent object, for example:

Intent. addflags (intent. flag_activity_clear_top | intent. flag_activity_new_task );

Note: If you want to use the app icon to return to the home page, you must call sethomebuttonenabled (true) from android4.0 (API Level 14) method To ensure that the icon can be used as an operation item (in previous versions, this icon can be used as an operation item by default ).

Navigate to the application superior page

As a supplement to the traditional back-to-back navigation (bringing users back to the previous window in the task history), you can enable the operation bar icon to provide the upper-level page navigation function, it brings the user back to the upper-level page of your application. For example, if you have a page with a deep application hierarchy on the current page, you should return the upper-level page (the parent page of the current page) when you touch the application icon ).

Figure 4. Standard icon (left) and navigation icon (right) of the email application ). The system automatically adds the up indicator.

For example, Figure 5 shows the "rollback" button action when a user navigating from an application to an activity belonging to a different application.

Figure 5. roll back the button after the people (or contacts) application enters the email application.

However, if you want to stay in the email application after editing the email, you can navigate up to the upper-level page of the editing email page in the email application, instead of returning to the previous activity. Figure 6 demonstrates this scenario. In this scenario, after you enter the email application, you do not press the back button, but navigate up by the action bar icon.

Figure 6. navigation from the people application to the email application.

If the application icon is able to navigate up, call the setdisplayhomeasupenabledtrue (true) method in your actionbar.

Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );

Setcontentview (R. layout. Main );
Actionbar = getactionbar ();
Actionbar. setdisplayhomeasupenabled (true );
...
}

When you touch this icon, the system calls the onoptionsitemselected () method with Android. R. Id. Home ID.

Remember to use the flag_activity_clear_top identifier in the intent object so that you can create a new instance without the existence of the parent activity. For example, if you do not use the flag_activity_clear_top identifier, it is strange to move the user to the lower-level page of the application by clicking the back button after navigation up.

NOTE: If many users can reach the path of the current activity in the application, the cursor should be gradually navigated along the actual startup path of the current activity.

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.