zoukankan      html  css  js  c++  java
  • ActionBarSherlock入门介绍

    最近做项目,需要用到ActionBarSherlock,所以想花点时间学习这个android开源库

    首先,百度百科介绍:

    ActionBarSherlock 是Android compatibility library 的一个扩展, 不知道什么原因 Android 兼容开发包没有包含ActionBar. 所以就有了ActionBarSherlock . 其使用方式和 兼容开发包类似.

    ActionBarSherlock 被设计成通过一个API就能够很方便使用所有版本的Android操作栏的设计模式

    源码下载网址:http://actionbarsherlock.com/

    以下内容主要从http://actionbarsherlock.com/usage.html翻译而来

    为了体验Android Ice Cream Sandwich版本及以上中才有的ActionBar功能,可以为项目加上ActionBarSherlock这个库。

    一:前提条件:
    1:这个库和你的项目的编译版本在Android 4.0以上
    2:你的编辑器及build系统,JDK版本要求在1.6以上

    二:把ActionBarSherlock包含进项目中
    1:如果你使用Eclipse环境及ADT(0.9.7版本及以上),使用actionbarsherlock/目录作为existing source创建一个Android项目,然后添加这个新建的项目到你的项目的libraries中(方法,右击项目->properties->Android->右下角Library中点击Add...添加库项目)
    2:如果使用ant从命令行编译,则
    If you use ant to compile from the command line you will need to run android update project -p . inside the actionbarsherlock/ folder of the project. Once completed, you can reference the actionbarsherlock/ folder of ActionBarSherlock from your application's project.properties file. For more information please see the Android developer guide for referencing library projects.
    3:如果使用maven来build你的Android项目,你可以简单的为这个库添加一个依赖

    1   <dependency>
    2     <groupId>com.actionbarsherlock</groupId>
    3     <artifactId>actionbarsherlock</artifactId>
    4     <version>4.1.0</version>
    5     <type>apklib</type>
    6   </dependency>

    三:ActionBar API
    当你的Activity在所有的Android版本中需要用到ActionBar,你可以声明你的Activity继承自Sherlock开头的任何Activity(例如:SherlockActivity、SherlockFragmentActivity)。与ActionBar交互只需要调用getSupportActionBar()而不是getActionBar()。这个ActionBar提供的方法调用和官方的是一样的
    需要注意一点:当使用SherlockFragmentActivity时,你应该使用带有"Sherlock"前缀的fragment来保证运行正常(例如:SherlockFragment、SherlockListFragment这些类)。这个SherlockFragmentActivity也能和官方的fragment运行,但这样的话你就不能使用menu相关的方法了。

    四:需要的主题
    ActionBar小部件比较复杂,它需要一套默认的主题。这个库提供了三个核心的主题,如果你想使用ActionBar的话,那么在你的Activity中必须使用其中一个主题

    五:导入类
    为了给Android3.0之前的版本提供ActionBar功能,这个库包含并使用了很多和官方类同名的类,最经常使用的是

    1 com.actionbarsherlock.app.ActionBar
    2 com.actionbarsherlock.view.Menu
    3 com.actionbarsherlock.view.MenuItem
    4 com.actionbarsherlock.view.MenuInflater

    你需要保证你引入的是这些类,因为他们包含额外的功能来支持ActionBar


    注意:
    1:关于 @Override-ing 的错误大部分是因为错误的引入。出现在com.actionbarsherlock.*;Package中的类如果和官方提供的类有重名,则代表他们继承自官方的类,他们可以在官方类出现的地方使用
    2:为了从XML文件中inflate你的menu文件,你应该使用getSupportMenuInflater()方法。(The fragment callbacks will already have an instance of the inflater as an argument这段我不知道是什么意思)
    这个ActionBar的核心用法和官方的ActionBar之间没有什么区别

    记得浏览以下界面:
    Theming:http://actionbarsherlock.com/theming.html
    Samples:http://actionbarsherlock.com/samples.html
    Frequently Asked Questions:http://actionbarsherlock.com/faq.html

    相关的介绍:
    ActionBar的API:http://developer.android.com/reference/android/app/ActionBar.html
    Fragment的API:http://developer.android.com/reference/android/app/Fragment.html
    ActionBar的设计范例、API、和常用例子:http://developer.android.com/guide/topics/ui/actionbar.html
    Menu相关UI介绍:http://developer.android.com/guide/topics/ui/menus.html
    Android兼容库:http://developer.android.com/tools/support-library/index.html#Using
    Fragments相关的介绍:http://developer.android.com/guide/topics/fundamentals/fragments.html

  • 相关阅读:
    java异常笔记
    CORBA IOR学习
    CORBA GIOP消息格式学习
    一个简单的CORBA例子
    Chrome 调试动态加载的js
    Android高效加载大图、多图解决方案,有效避免程序OOM(转)
    安卓开发笔记——打造万能适配器(Adapter)
    安卓开发笔记——个性化TextView(新浪微博)
    安卓开发笔记——关于Handler的一些总结(上)
    安卓开发笔记——关于AsyncTask的使用
  • 原文地址:https://www.cnblogs.com/creasylai19/p/3843860.html
Copyright © 2011-2022 走看看