5

All I want to do is change the accent color of my android app, but I'm having a tough time figuring out how to do that. The default for android is blue now, but I want to make it orange.

By accent color, I mean the accent of navigation tabs, the color that highlights when you hit lists, the accent color in pop up dialogs, etc.

I'm using actionbarsherlock if that matters.

Here is an image. I'd like to change the color of that blue accent throughout the app: enter image description here

jacosta
  • 349
  • 2
  • 5
  • 17

2 Answers2

6

It's been some time since you asked this question but now that google has released a new AppCompat version you can do what you want to achieve quite simply. The answer I'm giving you is inspired from android developer blog support library 2.2.1.

  1. Add the support library to your project (I am assuming you are using Android Studio).

    For that add these lines to the app.graddle file (assuming your module is named app).

    dependencies {
        compile 'com.android.support:appcompat-v7:22.2.0'
    }
    

  1. Set the theme of your application

    These lines are to be added to your styles.xml file. As you can see there are a few items in this style. If you want to know what element they correspond to go check customize android status bar with material.

    colorAccent is the color you want to change in the first place.

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="android:navigationBarColor">@color/navigationBarColor</item>
    </style>
    

    You will also need to set your application theme in the Android manifest

    <application
        android:theme="@style/AppTheme" >
    
        ...
    
    </application>
    

  1. Change From Activity / ActionBarActivity to AppCompatActivity in your classes.

    public class MainActivity extends AppCompatActivity
    {
         ....
    }
    

    You will probably need to change some methods due to the AppCompatActivity. Look at the video in the first link to better understand that :)


  1. Change your widgets to the AppCompat ones

    <LineareLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/text"
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_start" />
    
    </RelativeLayout>
    

Et voilà ! That's it you're all set :) You can now change the Accent color easily.

WannaGetHigh
  • 3,826
  • 4
  • 23
  • 31
2

You're going to want to use state layout lists.

http://developer.android.com/reference/android/content/res/ColorStateList.html

You might need to make one of these for each of the widgets that is going to have a new default selected color.

Michael
  • 3,334
  • 20
  • 27
  • I don't want to make new selected colors, I've used that type of tool for creating custom buttons. But I just wanna change the accent color, Let me add a screenshot to my question to explain better – jacosta Aug 02 '12 at 16:00
  • @user1519069 Try this: https://groups.google.com/forum/#!topic/actionbarsherlock/qej6FbZPnAI – Michael Aug 02 '12 at 16:28
  • Looks like that person was trying to do what I wanted, but it was never resolved – jacosta Aug 02 '12 at 16:53
  • Did you look at the styles sample that he referred him to? You might also try his original solution since it's possible the other guy just did something wrong. – Michael Aug 02 '12 at 17:01
  • have a look at the second answer of this question: http://stackoverflow.com/questions/13257219/android-change-holo-theme-default-blue-color – Bruno Bieri Jul 29 '13 at 12:53