"Android Interface Implementation" Actionbar use of a number of details of the collation

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/zhaokaiqiang1992

About the use of actionbar, a lot of great God has already written a very good article to introduce, so Actionbar basic use this article again, today we mainly discuss the Actionbar in the use of some of the details of the problem.

1. What is the mobile version limit for using Actionbar?

The native actionbar of the system was introduced in Android3.0 (API 11) to provide a unified-style navigation bar instead of the activity's title bar. For mobile phones, the version only exists in the 2.x era and 4.x era, because the 3.x system is generated for the tablet, there is no 3.x version of the system on the phone. Therefore, if the system native Actionbar is used, then the minimum version support for the software should be 4.0 (API 14). If we want to support a minimum of 2.2 systems, then the native Actionbar is not available, but we can use the third-party open source project Actionbarsherlock to achieve compatibility with the 2.x version. The use of this project is not introduced for the time being, a lot of information, the following is the project's GitHub address: Https://github.com/JakeWharton/ActionBarSherlock


2. What is the default Actionbar?

When we create a default version of 4.0 or more of the app, will bring a default effect of the Actionbar,actionbar from the function can be broadly divided into the following sections



What does the 3.Home area show?

Home location By default is used to place the app icon, but this location, can also be used to put a logo image. The difference between icon and logo is that icon refers to the app in the phone desktop icons, and logo is not limited, any picture can be, but in order to enhance the user's awareness of the brand, logo generally use the brand image. It is important to note that icon and logo cannot exist at the same time, if any logo,icon will be overwritten.


4. How do I specify whether to display icon or logo?

We can use the following method to develop an activity icon and logo properties

<activity            android:name= ". Mainactivity "            android:icon=" @drawable/ic_launcher "            android:label=" @string/app_name "            android:logo=" @drawable/qr ">        </activity>

After setting these properties, if you do not make any additional settings, the app will display the logo image by default, as shown in


What if we want to show icon?

Use the following code to

ActionBar = Getactionbar ();

ActionBar. setdisplayuselogoenabled (false);

The effect is as follows

What if we don't want the two icons? With the code below, you can remove the icon from the home.

Actionbar.setdisplayshowhomeenabled (FALSE);

5. How do I specify the caption text to display?

The title text area is used to indicate the current interface, which is divided into main headings and subheadings, and we can set the displayed caption in the following way.

<activity            android:name= ". Mainactivity "            android:icon=" @drawable/ic_launcher "            android:label=" @string/app_name "            android:logo=" @drawable/qr ">        </activity>
Of course, we can also control the displayed title and subtitle in the Code, like this:

Actionbar.settitle ("I am the main title"); Actionbar.setsubtitle ("I am the subtitle");

Here is the effect of the implementation

We can also hide the title through the following code

Actionbar.setdisplayshowtitleenabled (FALSE);


6. If you are in the home area, add an upward navigation icon?

If the click Effect of the home area is back to the previous level, then just using the icon is not appropriate, we can use the following code, the home area with the upward navigation icon, so that the navigation more clear

Actionbar.setdisplayhomeasupenabled (TRUE);

As follows:

With the upward navigation icon, we can accept this small icon of the click event, click on the eventonoptionsitemselected inside Accept, the code is as follows

@Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar will//automatically handle clicks on the Home/up button so long//as you specify a parent activity in and RoidManifest.xml.int id = item.getitemid (); if (id = = r.id.action_settings) {return true;} if (id = = Android. R.id.home) {Toast.maketext (This, "click", Toast.length_short). Show (); return true;} return super.onoptionsitemselected (item);}

Because this position is set by the system, the ID is the fixed android. R.id.home, we're inonoptionsitemselected can receive the click event, then the corresponding logic processing.

Another idea is to use the logo described above, the logo is set to return the icon, you can achieve similar effects.

    7. How to set the custom background or color for Actionbara

Actionbar comes with only black and white colors, and if we want to change the color of actionbar, we can use a picture or a pure color value.

If you use a custom picture, we can do the following

drawable d = getresources (). getdrawable (r.drawable. Ic_launcher);

ActionBar. setbackgrounddrawable (d);

The effect is as follows


If we use a custom color, we can do it like this

ActionBar. setbackgrounddrawable (new colordrawable (Color. BLUE));

The effect is as follows



"Android Interface Implementation" Actionbar use of a number of details of the collation

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.