Change the background color of an ActionBarSherlock programmatically

I have an ActionBarSherlock in my form. I read style information at runtime. One style element is the background color of the ActionBar. How can I change this at runtime? The color can be any RGB value.

+6
source share
3 answers

Maybe this help: How to set title color in ActionBarSherlock? via style or getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak)); with software

With the topic

 // add theme in app <application android:theme="@style/MainTheme"></application> // MainTheme <style name="MainTheme" parent="Theme.Sherlock.Light.DarkActionBar"> </style> // MainThemeGreen <style name="MainThemeGreen" parent="Theme.Sherlock.Light.DarkActionBar"> <item name="android:actionBarStyle">@style/MainTheme.ActionBarStyle</item> </style> // ActionBar <style name="MainTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar"> <item name="android:background">@drawable/bg_green_actionbar</item> <item name="android:titleTextStyle">@style/MainTheme.ActionBar.TitleTextStyle</item> </style> // Text style <style name="MainTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title"> <item name="android:textColor">@color/White</item> </style> // bg_green_actionbar.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape> <solid android:color="#ff74af3b" /> </shape> </item> </layer-list> 

After that, you can change the theme on the fly: setTheme (R.styles.MainThemeGreen);

+8
source

One of the methods:

 mSupportActionBar = getSupportActionBar(); mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456)); 

where 0xff123456 is your required ARGB integer.

+6
source

I just used the code below

  getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00853c"))); 

he changed the color bg. Hope this helps.

+5
source

Source: https://habr.com/ru/post/915429/


All Articles