[Translation] action bar for Android

Source: Internet
Author: User
ArticleDirectory
    • In the layout file
    • In activity, homeaction is in the leftmost bar, while normal action is in the rightmost bar.
    • Custom Action
    • Title Click Event
    • Customization
    • Want to contribute?

ThisProjectDesigned to provideReusableAction bar. For more information about the action bar mode, seeAndroid patterns.

The action bar component is a library project, which means that you do not need to copy resources to a project. You only need to reference the action bar component to the project.

Does action bar require icons?

Need icons to your action bar? Olof brickarp has ported some of androids native icons to vector format.

Used in the layout File
<COM. markupartist. android. widget. actionbar Android: Id = "@ + ID/actionbar" app: Title = "@ string/some_title" style = "@ style/actionbar"/>

APP: The title is optional.ProgramUse settitle to set the title for the actionbar.

The useAPP: TitleIs optional, it's also possible to assign the title usingSettitleProgrammatically onActionbar. To be able to use the more convenientAPP: Title
The application namespace must be encoded in the same manner as
Android namespace is. Please refer to the layout other. XML in
Example project for a full example. Again, note that it's
Application namespace andNotThe actionbar namespace that must be referred likeXmlns: APP = "http://schemas.android.com/apk/res/you.application.package.here".

In activity, homeaction is in the leftmost bar, while normal action is in the rightmost bar.
Actionbar = (actionbar) findviewbyid (R. id. actionbar); // You can also assign the title programmatically by passing a // charsequence or resource ID. // actionbar. settitle (R. string. some_title); actionbar. sethomeaction (New intentaction (this, homeactivity. createintent (this), R. drawable. ic_title_home_default); actionbar. addaction (New intentaction (this, createshareintent (), R. drawable. ic_title_cmd_default); actionbar. addaction (New toastaction ());
Custom Action

To create a custom action, you only need to implement one action interface. For example:

 
Private class toastaction implements action {@ override public int getdrawable () {return r. drawable. ic_title_export_default;} @ override public void upload maction (view) {toast. maketext (otheractivity. this, "example action", toast. length_short ). show ();}}
Title Click Event

To process the title click event, you only need to callSetontitleclicklistener method, setAndroid. View. View. onclicklistener. In The onclick method, the view object is the textview of the title.

 
Actionbar. setontitleclicklistener (New onclicklistener () {public void onclick (view v) {// your code here }});
Customization

Because actionbar is a library project, all resources are merged into the new project by reference. The parameters set in the new project will overwrite the default parameters specified in the actionbar.

If you do not like the default parameters set by actionbar in colors. XML, you only need to overwrite the default settings in colors. XML in the new project. To set a blue actionbar, you only need to set it in colors. XML as follows.

 
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <color name = "actionbar_separator"> # 3a5fcd </color> <color name = "actionbar_background_start"> # 3a5fcd </color> <color name = "actionbar_background_end"> # 27408b </color> </resources>

Similarly, you can overwrite drawables, layouts, and other actionbar attributes in the new project.

Contributions

This widget wouldn't be the same without the excellent contributions;

    • Ohhorob https://github.com/ohhorob
    • Denravonska, https://github.com/denravonska
    • Rpdillon, https://github.com/rpdillon
    • Rickardpettersson, https://github.com/RickardPettersson
    • Jake Wharton, https://github.com/JakeWharton
    • Jesse Vincent, http://blog.fsck.com
    • Gyuri Grell, http://gyurigrell.com
Want to contribute?

GitHub has some great articles on how to get started with GIT and GitHub and how to fork a project.

Contributers are recommended to fork the app on GitHub (but don't
Have too). Create a feature branch, push the branch to git hub, press
Pull request and write a simple explanation.

One fix per commit. If say a commit closes the open issue 12. Just addCloses #12In your commit message to close that issue automagically.

All code that is contributed must be compliant with Apache license 2.0.

Code style guidelines

Contributers are recommended to follow the android code style guidelines with exception for line length that I try to hold to 80 columns where possible.

In short that is;

    • Indentation: 4 spaces, No tabs.
    • Line Length: 80 columns
    • Field Names: Non-public, non-static fields start with M.
    • Braces: Opening braces don't go on their own line.
    • Acronyms are words: Treat acronyms as words in names, yielding XMLHttpRequest, geturl (), etc.
    • Consistency: Look at what's around you!

Have fun and remember we do this in our spare time so don't be too serious

https://github.com/johannilsson/android-actionbar

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.