Cameron
Cameron

Reputation: 184

How to Customize the Android Action Bar?

My Android App's Action Bar doesn't display the icon defined in the tag of the 'AndroidManifest.xml" nor am I able to change things such as colour of the action bar, or the colour of the title text on the action bar.

I am currently using minimum API 16 (Android Jellybean 4.1) and target SDK as the latest (at the time of writing) which is 22.

My styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBar</item>
    </style>

    <style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#006699</item>
    </style>
</resources>

My AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PACKAGE_NAME" >

<application
    android:allowBackup="true"
    android:icon="@drawable/logo_custom"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:logo="@drawable/logo_custom"
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Whenever I test the app on my phone (running 4.4.4 KitKat API 19) I just get the default black action bar with no application icon.

Does anyone know why this won't customize?

All help is appreciated, thanks in advance.

Note: I am new to Android Development.

Upvotes: 0

Views: 1484

Answers (3)

Half Moon
Half Moon

Reputation: 589

<style name="Theme.AndroidDevelopers" parent="android:style/Theme.Holo.Light">
    <item name="android:selectableItemBackground">@drawable/ad_selectable_background</item>
    <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
    <item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
    <item name="android:listChoiceIndicatorMultiple">@drawable/ad_btn_check_holo_light</item>
    <item name="android:listChoiceIndicatorSingle">@drawable/ad_btn_radio_holo_light</item>
</style>

For More: Android ActionBar

Upvotes: 0

Rajesh Jadav
Rajesh Jadav

Reputation: 12861

Try this in your Styles.xml.

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
        <!-- Support library compatibility -->
        <item name="colorControlNormal">@color/light_gray</item>
        <item name="background">@color/white</item>
        <item name="android:textColor">@color/white</item>
    </style>

EDIT:

You can change background of Actionbar programatically.

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_background_color)));

You have to define your color code in color.xml like this.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="actionbar_background_color">#f4f2f2</color>
</resources>

Upvotes: 1

Adarsh Yadav
Adarsh Yadav

Reputation: 3770

I would suggest to use Toolbar as it provide almost all customization which you want to do with action bar, You will find a working example here

Upvotes: 0

Related Questions