ActionBar 改变样式并兼容sdk 11以下机器的方法

最近在编辑action bar的样式,很烦恼,大家知道holo等样式是不能使用在3.0以下的机器的,弄了很久,最终在一个在线编辑网站完成了工作。

该网站可以在线产生三种格式的action bar。大家也应该知道,为了兼容android sdk 3.0/11 版本以下的机器,需要引入第三方包或者谷歌的兼容包,常用的方法是引入android Compat v4 v7包或者是引入Sherlock action bar包。以下网站可以很好的帮android开发者完成工作。


网站网址是:http://jgilfelt.github.io/android-actionbarstylegenerator/


附件和下面的代码,是我使用该网站编辑的action bar样式,action bar完全适配2.3以上的机器,兼容包使用的是android 自带的android-support-v7-appcompat包


下面这个是处于value包底下的style文件,是为了提供给3.0以下的机器使用的


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.Itnews" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarItemBackground">@drawable/selectable_background_itnews</item>
        <item name="popupMenuStyle">@style/PopupMenu.Itnews</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Itnews</item>
        <item name="actionBarTabStyle">@style/ActionBarTabStyle.Itnews</item>
        <item name="actionDropDownStyle">@style/DropDownNav.Itnews</item>
        <item name="actionBarStyle">@style/ActionBar.Solid.Itnews</item>
        <item name="actionModeBackground">@drawable/cab_background_top_itnews</item>
        <item name="actionModeSplitBackground">@drawable/cab_background_bottom_itnews</item>
        <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Itnews</item>
        <item name="homeAsUpIndicator">@drawable/ic_upper</item>
        <item name="displayOptions">showHome|homeAsUp</item>
    </style>

    <style name="ActionBar.Solid.Itnews" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="background">@drawable/bg_actionbar</item>
        <item name="backgroundStacked">@drawable/ab_stacked_solid_itnews</item>
        <item name="backgroundSplit">@drawable/ab_bottom_solid_itnews</item>
        <item name="progressBarStyle">@style/ProgressBar.Itnews</item>
    </style>

    <style name="ActionBar.Transparent.Itnews" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="background">@drawable/ab_transparent_itnews</item>
        <item name="progressBarStyle">@style/ProgressBar.Itnews</item>
    </style>

    <style name="PopupMenu.Itnews" parent="@style/Widget.AppCompat.Light.PopupMenu">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_itnews</item>
    </style>

    <style name="DropDownListView.Itnews" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_itnews</item>
    </style>

    <style name="ActionBarTabStyle.Itnews" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_itnews</item>
    </style>

    <style name="DropDownNav.Itnews" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/spinner_background_ab_itnews</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_itnews</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_itnews</item>
    </style>

    <style name="ProgressBar.Itnews" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_itnews</item>
    </style>

    <style name="ActionButton.CloseMode.Itnews" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_itnews</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Itnews.Widget" parent="@style/Theme.AppCompat">
        <item name="popupMenuStyle">@style/PopupMenu.Itnews</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Itnews</item>
    </style>

</resources>


下面这个是位于android工程values-v14包下的style文件的内容


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.Itnews" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_itnews</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Itnews</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Itnews</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Itnews</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Itnews</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Itnews</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_itnews</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_itnews</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Itnews</item>
        <item name="android:homeAsUpIndicator">@drawable/ic_upper</item>
        <item name="android:displayOptions">showHome|homeAsUp</item>
    </style>

    <style name="ActionBar.Solid.Itnews" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@drawable/bg_actionbar</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_itnews</item>
        <item name="android:backgroundSplit">@drawable/ab_bottom_solid_itnews</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Itnews</item>
    </style>

    <style name="ActionBar.Transparent.Itnews" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@drawable/ab_transparent_itnews</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Itnews</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Itnews.Widget" parent="@style/Theme.AppCompat">
        <item name="android:popupMenuStyle">@style/PopupMenu.Itnews</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Itnews</item>
    </style>

</resources>


资源包下载地址:

敲击我下载

你可能感兴趣的:(样式,Actionbar,兼容)