6

I generated actionbar style using this web based tool which is very common http://jgilfelt.github.io/android-actionbarstylegenerator/

I've 'android-support-v7-appcompat' as an individual project in my workspace. I dumped all the contents of the res folder generated by downloading the zip file from this tool into this project.

I used a dark blue kinda color for the action bar and context menu (pop up). However, I'm not able to achieve the custom look from this theme. Most of the elements / components show a default look. The actionbar is black (instead of blue) and the pop menu is grey (instead of light blue)

My style.xml from the value folder

<style name="Theme.dinemobileandro" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarItemBackground">@drawable/selectable_background_dinemobileandro</item>
    <item name="popupMenuStyle">@style/PopupMenu.dinemobileandro</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.dinemobileandro</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.dinemobileandro</item>
    <item name="actionDropDownStyle">@style/DropDownNav.dinemobileandro</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.dinemobileandro</item>
    <item name="actionModeBackground">@drawable/cab_background_top_dinemobileandro</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_dinemobileandro</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.dinemobileandro</item>

            <!-- Light.DarkActionBar specific -->
    <item name="actionBarWidgetTheme">@style/Theme.dinemobileandro.Widget</item>

</style>

I've made the necessary changes in my manifest file as well

  <application
   android:name="com.railyatri.in.mobile.MainApplication"
   android:allowBackup="true"
   android:allowClearUserData="true"
   android:enabled="true"
   android:icon="@drawable/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/Theme.dinemobileandro" >

I've followed the steps mentioned in this blog closely and it worked for me previously for a sherlock theme. http://java.dzone.com/articles/creating-custom-android-styles However, this time, I migrated to appcompat and it stopped working. I've searched through SO and Google a lot and tried a couple of things suggested but all in vain.

Please help. Thanks in advance.

user1006072
  • 953
  • 5
  • 20
  • 29
  • May this help you http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us/27847656#27847656 – Apurva Feb 20 '15 at 13:59
  • Thanks @Apurva but it didn't work. I am doing the same thing. Almost hitting a dead end here. – user1006072 Feb 21 '15 at 06:43
  • Which version ofA ppcompat ? – Gabriele Mariotti Feb 21 '15 at 07:35
  • @GabrieleMariotti, I am using appcompat V21 along with android -support -v7- appcompat. Thanks for your interest – user1006072 Feb 21 '15 at 07:51
  • I dont understand if you dumped the content of the res folder from tool to the res folder of the library appcompat-v7 or to the res folder of your own project. – GPack Feb 21 '15 at 16:33
  • @GPack, I dumped the content in the res folder of the library appcompat-v7 and not in my projects app folder. – user1006072 Feb 25 '15 at 12:10
  • This is an unusual way and with the risk to overlay the original contents of the library. Maybe it happened so. – GPack Feb 25 '15 at 12:36

4 Answers4

5

With AppCompat v21 the actionbarstylegenerator is deprecated.

You can use something like this to customize the ActionBar (or better the Toolbar).

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- Set AppCompat's color theming attrs -->
    <item name="colorPrimary">@color/my_color</item>
    <item name="colorPrimaryDark">@color/my_darkercolor</item>
    
</style>

You can find more info in the official blog: http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html

John Glen
  • 771
  • 7
  • 24
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks @Gabriele Mariotti, I ended up moving to ToolBar but I wish I had a way to work with action bar as I was more comfortable with it already. I am not running into multiple issue with Toolbar such as the height of the toolbar is too big which I am not able to reduce. The app icon shows too big as well and the croutons are showing above the toolbar that too clipped off. I guess, it's just a big research activity – user1006072 Feb 21 '15 at 11:38
0

On Android manifest:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/Theme.dinemobileandro" >

On styles xml:

<style name="Theme.dinemobileandro" parent="AppTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/blue</item>
<item name="background">@drawable/blue</item>

On drawables xml:

<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
    <drawable name="blue">#6189C5</drawable>
</resources>

The toolbar on activity is blue (#6189C5) compiling with API 21

Completed with the info in this answer (like Apurva appointed)

Community
  • 1
  • 1
Javi Mollá
  • 786
  • 7
  • 18
  • Thanks @Javier. I tried this but it changed the whole app to be that color. It was blue all over. I just wanted the action bar to be blue. – user1006072 Feb 20 '15 at 17:02
  • Thanks again. Tried what you said but didn't work. The app is back to what it was. The blue is not taking effect. Black actionbar and grey context menu. – user1006072 Feb 21 '15 at 06:34
  • @user1006072 the answer @javier suggested is my answer. If all your activities are changed with blue actionbar then you must be putting the custom theme in `` tag of `manifest` file. Put `android:theme="@styles/custom_theme"` only in the `` tag you want to change actionbar color of. And you say your overflow menu still has **grey** color, then you must be compiling your app with api level 21. Android has stopped supporting overflow menu color with this solution in api 21. – Apurva Feb 21 '15 at 08:30
  • @Apurva, I didn't apply it at the application level. I applied it to the activity itself. However, it still turned that whole activity to be blue. – user1006072 Feb 21 '15 at 11:34
  • @user1006072 no it cannot make an entire activity blue, you must be making any mistake. Did you see my answer? I have tried it many many times, it cannot apply blue color to your activity. – Apurva Feb 21 '15 at 11:40
  • Edit your question and post your changes applying what @Apurva suggested – Javi Mollá Feb 21 '15 at 12:25
  • Thanks for your response fellas. I ended up moving to toolbar and ditched the action bar altogether as suggested by @Gabriele above. I am sure yours is a workable solution as well but moving to toolbar gives me other advantages specific to Android 5 / Material design. – user1006072 Feb 25 '15 at 12:09
0

Have your already tried to change on your Java file? Something like this:

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.ic_launcher);
    getSupportActionBar().setTitle(Html.fromHtml("<font color=\"grey\">" + getString(R.string.app_name) + "</font>"));
    getSupportActionBar().setBackgroundDrawable(..);
porthfind
  • 1,581
  • 3
  • 17
  • 30
  • No, I haven't. Will give it a try and let you know. However, I didn't have to do it when I was using Sherlock Action Bar. Neither did I find any of the blogs / tutorial that I referred to asking me to change the Java files. – user1006072 Feb 20 '15 at 17:04
0
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">

    <item name="colorPrimary">@color/my_actionbar_color</item>
    <item name="colorPrimaryDark">@color/my_actionbar_dark_color</item>

    <!-- if you need customization -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>

Remember to use

parent="Theme.AppCompat.Light"

not

parent="@style/Theme.AppCompat.Light"
heloisasim
  • 4,956
  • 2
  • 27
  • 36