"Android Interface implementation" Actionbar take advantage of some of the details of finishing

Source: Internet
Author: User

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

About the use of Actionbar, very much God has already written a very good article to introduce, so the basic use of Actionbar this article to repeat. Today we mainly discuss some of the details of Actionbar in use.

1. What is the phone version number limit for using Actionbar?

The native actionbar of the system was introduced in Android3.0 (API 11) and was used primarily to provide a unified-style navigation bar. To replace the activity's title bar. For mobile phones, the version number only exists in the 2.x era and the 4.x era. This is because the 3.x system is generated for the tablet, there is no 3.x version number on the phone system. So, suppose the system native Actionbar is used. Then the minimum version number support for the software should be 4.0 (API 14). Assuming we want to support a minimum of 2.2 systems, the native Actionbar cannot be used, just. We are able to use third party open source projects Actionbarsherlock. achieve compatibility with 2.x version numbers.

The use of this project is not introduced on a temporary basis. The information is very much, the following is the project's GitHub address: Https://github.com/JakeWharton/ActionBarSherlock


2. What is the default Actionbar?

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

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvemhhb2thaxfpyw5nmtk5mg==/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center "/>


What does the 3.Home area show?

The home location is the default icon used to place the app. But this position, can also be used to put a logo image.

The difference between icon and logo is. Icon refers to the app on the phone desktop icons, and logo is not limited, no matter what the 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 can not exist at the same time, fake with logo. Icon will be overwritten.


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

We are able to use the following methods. To develop an activity's icon and logo properties

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

After you have set these properties. If you do not make any additional settings, the app will display the logo image by default. For example, as seen in the


What if we want to show icon?

Use the following code to

ActionBar = Getactionbar ();

ActionBar. setdisplayuselogoenabled (false);

Effects such as the following

What if we don't want both of these icons? Pass the following code. will be able to remove the home icon.

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 are the effects of the implementation

We can also hide the title with the following code

Actionbar.setdisplayshowtitleenabled (FALSE);


6. Suppose the home area, plus the up navigation icon?

Let's say the Click Effect in the Home area is back to the previous level. So just using the icon is not a good idea, we can use the following code, the home area with an upward navigation icon, so that the navigation more understanding

Actionbar.setdisplayhomeasupenabled (TRUE);

For example, the following:

With the upward navigation icon, we are able to accept the Click event of this small icon. The Click event isonoptionsitemselected inside Accept. Code such as the following

@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);}

Since this position is set by the system. So the ID is 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 to set the logo back to the icon. can also achieve similar results.

    7. How to set your own defined background or color for Actionbara

The color of the actionbar comes with only black and white. Let's say we want to change the color of Actionbar. We can use a picture or a pure color value.

Assuming you use your own definition picture, we can do the following

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

ActionBar. setbackgrounddrawable (d);

Effects such as the following


Assume that you use a color that you define. We can do this like this

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

Effects such as those seen below



"Android Interface implementation" Actionbar take advantage of some of the details of finishing

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.