1

I am trying to personilize my action bar. I want it to support API-9 and above the problem is that action bar doesn't accept changed made in styles.xml and items are not shown.

this is my styles.xml :

<resources>

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

    <style name="AppTheme" parent="AppBaseTheme">

        <item name="android:windowBackground">@color/background_window</item>
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <!--<item name="android:icon">@drawable/ic_launcher</item>-->
        <item name="android:background">#ff127d08</item>
    </style>

</resources>

the application is just showing the default action bar without icon neither items or background that i choosed

  • It was working fine, until i changed in my main activity, i was extending from Fragments but now i extend from ActionBarActivity, and also i changed getActionBar() calls to getSupportActionBar() –  May 26 '15 at 11:41

2 Answers2

2

The official way to set the action bar color with appcompat-v7 is via colorPrimary on the activity theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Apptheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
  </style>
</resources>

With regards to the icon, this has been asked many, many times, and the answer (getSupportActionBar().setDisplayShowHomeEnabled(true); and getSupportActionBar().setIcon(R.drawable.ic_launcher);) can be found via Web searches for appcompat icon.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • ok it works but the problem is that the action bar doesn't show items ! plz what can i do to fix that problem ? –  May 26 '15 at 12:06
1

Go for Custom theme , add themes.xml inside res-->values folder

use this code for custom actionbar

themes.xml

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

    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>

        <!-- Support library compatibility -->

        <item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
         <item name="android:actionBarTabBarStyle">@style/Divider</item>
    </style>

<!-- for Tab divider -->
<style name="Divider" parent="@android:style/Widget.Holo.ActionBar.TabBar">
    <item name="android:divider">@android:color/transparent</item> //or use your transparent drawable image
    <item name="android:showDividers">middle</item>
    <item name="android:dividerPadding">0dp</item>
</style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/easy</item>
        <!-- Support library compatibility -->
        <item name="background">@color/easy</item>
    </style>

    <style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:background">@drawable/actionbar_tab_indicator</item>
    </style>

    <style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">

        <!-- This is a Black text color when selected and a WHITE color otherwise -->
        <item name="android:textColor">@color/selector_tab_text</item>
    </style>

</resources>

manifest file call -->CustomActionBarTheme

<application
        android:allowBackup="true"
        android:icon="@drawable/easylogo"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/CustomActionBarTheme" >


        <activity
            android:name="com.example.Start"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 </application>
Android Dev
  • 421
  • 8
  • 26