ActionBarの背景と文字を変更してみよう!


よくあるこんな感じのActionbarの背景を変更してみます。

必要なもの

・colors.xml
色情報を格納するためのXMLファイルです。
格納する場所はres/valuesに入れます。
valuesの中には他にdimens.xmlやstrings.xmlといったファイルが入ってると思います。

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="start_color">#e56200</color>
    <color name="end_color">#FFE1CC</color>
</resources>

・gradation.xml
Actionbarに使う背景色です。
drawableのフォルダの中に格納します。

gradation.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:startColor="@color/start_color"
        android:endColor="@color/end_color"
        android:type="linear"
    />
</shape>

色はこんな感じです。

・styles.xml
アプリのデザイン(スタイル)を決めるXMLファイル。
一言で言えばCSSみたいなものです。

styles.xml
<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="android:Widget.Holo.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/ActionBarTitleStyle</item>
        <item name="android:subtitleTextStyle">@style/ActionBarSubitleStyle</item>
        <item name="android:background">@drawable/gradation</item>
        <item name="android:backgroundStacked">@android:color/white</item>
    </style>

    <style name="ActionBarTitleStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textStyle">bold|italic</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

    <style name="ActionBarSubitleStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
        <item name="android:typeface">monospace</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

</resources>

うまく適用できました!٩('ω' )و