?
转自:http://blog.csdn.net/hnxxwyq/article/details/8632769
?
?
?
在android中2.3.x使用ActionBar,需要有actionbarshelock的支持,至于这么加入actionbarshelock的支持,可以移步这里-开源组件actionbarsherlock的使用
?
建立样式文件values/themes.xml,内容如下
?
- <?xml?version="1.0"?encoding="utf-8"?>??
- <resources?xmlns:android="http://schemas.android.com/apk/res/android">??
- ????<!--?父类为Theme.Sherlock.Light,即白底黑字(如果是Theme.Sherlock,则为黑底白字),?为了兼容考虑,所有样式的相关item需要写2遍-->????
- ????<style?name="Theme.DEMO"?parent="Theme.Sherlock.Light">??
- ????????<item?name="actionBarStyle">@style/Widget.DEMO.ActionBar</item>??
- ????????<item?name="android:actionBarStyle">@style/Widget.DEMO.ActionBar</item>??
- ????</style>???
- ??????
- ????<!--?标题栏的样式?-->??
- ????<style?name="Widget.DEMO.ActionBar"?parent="Widget.Sherlock.ActionBar.Solid">?????
- ????????<item?name="background">#1791d2</item>??
- ????????<item?name="backgroundStacked">#1791d2</item>??
- ????????<item?name="backgroundSplit">#1791d2</item>??
- ????????<item?name="titleTextStyle">@style/Widget.DEMO.ActionBar.Title</item>??
- ??????????
- ????????<item?name="android:background">#1791d2</item>??
- ????????<item?name="android:backgroundStacked">#1791d2</item>??
- ????????<item?name="android:backgroundSplit">#1791d2</item>??
- ????????<item?name="android:titleTextStyle">@style/Widget.DEMO.ActionBar.Title</item>??
- ????</style>??
- ??????
- ????<!--?标题栏的标题样式?-->??
- ????<style?name="Widget.DEMO.ActionBar.Title"?parent="@android:TextAppearance.Holo.Widget.ActionBar.Title">??
- ????????<item?name="android:textColor">#fff</item>??
- ????</style>??
- ??????
- </resources>??
?
?
而activity类则需要继承自SherlockActivity?或者 SherlockFragmentActivity
?
- package?com.game178.lolmobiledhelper;??
- import?android.os.Bundle;??
- import?com.actionbarsherlock.app.SherlockFragmentActivity;??
- public?class?ItemInfo?extends?SherlockFragmentActivity?{??
- ????@Override??
- ????protected?void?onCreate(Bundle?savedInstanceState)?{??
- ????????super.onCreate(savedInstanceState);??
- ????????setContentView(R.layout.item_info);??
- ????}??
- }??
效果如下
?
?
参考自:https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/TiJYM_TKhb8?