How can I change the style of action bar API 15

2019-01-29 10:00发布

问题:

I want to change the style of my Action bar so I want to change the color of line under the action bar from Blue to Orange , how can I do that?

回答1:

There is a good tutorial here

Create a new style with your custom drawable

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="Theme.MyStyle" parent="@android:style/Theme.Holo">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <!-- other activity and action bar styles here -->
    </style>

    <!-- style for the action bar backgrounds -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:background">@drawable/ab_background</item>
        <item name="android:backgroundStacked">@drawable/ab_background</item>
        <item name="android:backgroundSplit">@drawable/ab_split_background</item>
    </style>
</resources>

then in AndroidManifest.xml add the custom style

<application
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"

        android:theme="@style/Theme.MyStyle"
        >
   <activity ...>
   <activity .../>
   ...

</application>


回答2:

If you want change it by code, you could try this:

getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.myninepatch));