ActionBar in API 8-10 in Android

人走茶凉 提交于 2019-12-04 19:39:41

ActionBar added in Android 3.0 (API level 11), but you can use it in ealier API 11 by using Spport Library. To use support library for Action Bar, your activity should extends ActionBarActivity.

To custom your action bar color, you can set actionbar style in styles.xml file, something like:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">                
    <item name="actionBarStyle">@style/MyActionBar</item>

</style>


<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- for before API 11 -->
    <item name="background">@color/your_color</item>
    <!-- for after API 11 -->
    <item name="android:background">@color/bg_blue</item>
</style>

Hope this help!

[UPDATE]

To use AppCompat theme, you have to import AppCompat library to your project from support library V7: your-android-sdk\platforms\extras\android\support\v7\appcompat

In one of my projects, I used ActionBarSherlock.

  1. Download the abs here.

  2. Assuming you're using Eclipse IDE, right click your project, click properties, then android. At the bottom, in layout, add abs.

  3. Make sure abs and your project are in the same directory.

  4. Extend your classes to Sherlock naming. For example, instead of Activity, change it to Sherlock Activity. The main documentation of abs is found here.

  5. For easier usage of Sherlock, create util methods in changing the Sherlock names and modifying it.

Here is a sample code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!