Search code examples
androidactionbarsherlock

Change SherlockActionBar line color dynamically


I want to change the color of the bottomline of the sherlock actionbar.

enter image description here But I want to change it dynamically.

When the user is offline I want it to appear red, when he is logging on I want it orange and when he is succesfully connected the line should be green.

How can I achieve this?
Thanks.


Solution

  • I found a solution in case anyone wants to do this.
    I used this website to make 3 styles and took the 'ab_transparent' resource out of the zip.

    To set the actionbar on runtime I used

    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_transparent_connecting));   
    

    Sidenote: this worked perfectly on android 4.0+ but on <4.0 I had to call

    this.supportInvalidateOptionsMenu();

    after setting the backgrounddrawable for it to take effect.