I have added ActionBar tabs to my application. Default color for that underline is light blue. How do I change that color or style for selected tab ?
For anyone wants to change actionbar color/background in code, you can do something like this
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_bg));
To change the tab bar color under the actionbar:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_brown_dark)));
To change tab bar background:
actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
R.drawable.coupon_header));
This may give some clues Action Bar Style Gen
selectableItemBackground is the attribute I think your looking for.
I'd recommend you read this article about Customizing the Action Bar as well as look at this question on SO and this one as well.
In code i cant seem to find a way to customize the individual item selected but , customizing the bar itself would look something like this.
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("FF0000"));
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// set background for action bar
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0c2354")));
// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));
bar.show();
Here is a much easier way:
I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set colorAccent in your theme and that will change the highlight color on your ActionBar. Like so:
<item name="colorAccent">#color/highlightcolor</item>
Here it is in context:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/darkgrey</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/highlightcolor</item>
</style>
Where I originally posted this answer: Android Tab underline color not changing
1) Generate the Action Bar Style, click Download ZIP to get the files
2) When you extract the zip file created in Step 1, you will get a res folder. Add this folder to your project under platform/android.
3) Modify manifest.xml to Use the New Action Bar Style, where "Action" is name of your style set in step 1.
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>14</tool-api-level>
<manifest>
<application android:theme="#style/Theme.Action"/>
<uses-sdk android:minSdkVersion="14"
android:targetSdkVersion="16"/>
</manifest>
</android>
This manual helped me and I hope it will help you too.
Related
I have a style file where i am setting some action bar style like this
<style name="ActionBar.Solid.Pro" parent="#style/Widget.Sherlock.ActionBar.Solid">
<item name="background">#color/dialer_color</item>
<item name="backgroundStacked">#color/dialer_color</item>
<item name="backgroundSplit">#color/dialer_color</item>
<item name="android:progressBarStyle">#style/ProgressBar.Pro</item>
</style>
Now i want to change the color of action bar programmatically like this`
getSupportActionBar.setBackgroundDrawable(new ColorDrawable(Color.Red));
But it do not have any effect. Can you please tell me why , where i am doing wrong
Is it possible to change the ActionBar.TabView background programatically ?
I am setting my style like this, how can i change the background of this style attribute ?
<style name="ActionBarTabStyle.Pro" parent="#style/Widget.Sherlock.ActionBar.TabView">
<item name="android:background">#color/dialer_color</item>
</style>
See you can refer to android action bar style generator
That makes the work of customising the action bar much easier
I advice you that you must have a look on this link
It will surely help you
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=holo&theme=light&actionbarstyle=solid&texture=0&hairline=0&neutralPressed=1&backColor=E4E4E4%2C100&secondaryColor=D6D6D6%2C100&tabColor=33B5E5%2C100&tertiaryColor=F2F2F2%2C100&accentColor=33B5E5%2C100&cabBackColor=FFFFFF%2C100&cabHighlightColor=33B5E5%2C100
And one more thing when you will be done with specifying the colors then you will receive the set of images in an archive i.e. .zip format
So you must extract them in their respective folders or directories
In the directory naming "res"
My suggestion is to drop the ActionBar alltogether and use the new Toolbar from the AppCompatLibrary V21. There you just specify Primary and Accent Colors and your background will be set, as well as all controls on it.
For starters this is described in the blog from Chris Banes:
appcompat v21: material design for pre-Lollipop devices!
I am using sherlock actionbar and made custom action bar using differnt color (blue) . When there are menu items . as i click on menu item . items background turns in to gray . Not able to point which attribute of the style is making this effect had checked the most possibility . any help would be appreciated
after some analysis found following answer
<item name="selectableItemBackground">#null</item>
<item name="android:selectableItemBackground">#null</item>
<item name="actionBarItemBackground">#null</item>
<item name="android:actionBarItemBackground">#null</item>
The issue is you need to override these attributes in your application. donot try changing in actionbar apk libary. that was the point i missed while fixing this.
So I've basically looked into every resource I saw online on how to change the blue underline in the tabs, but all of the advice has not worked in my case.
I tried actionbarsherlock, appcombat, holo from Action Bar Generator but all the coloring did was color the top action bar, not the tab underline. And yes the files did compile and did not have any errors, but for some reason, it seemed like the underline would never be changed even through the generator.
I am confused on how to change the default blue underline on the tabs, and I would SO EXTREMELY appreciate it if there was a working custom style xml that you would share.
After going to Changing ActionBar tabs underline color programmatically result is still same :/
Screen shot after trying from other page: http://i.stack.imgur.com/EOUbu.png
Anyone able to help me out?
I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set colorAccent in your theme and that will change the highlight color on your ActionBar. Like so:
<item name="colorAccent">#color/highlightcolor</item>
Here it is in context:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/darkgrey</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/highlightcolor</item>
</style>
You need to define a custom theme for that, and then check the states to change the colour of the line. See if this answer helps you
Not sure if you are still pursuing this, but can you show what you did with Action Bar Generator? What Style entries did you add (in XML) and which drawables did you add?
I just went through the same process and it worked well with Action Bar Generator; just required a few lines added to the styles.xml, a new xml file in drawables folder, and then about 5 new image drawables into each of the resolution size folders (drawable-hdpi, etc).
I've used "Android Action Bar Style Generator" in order to generate my own Holo theme.
Then I've added two icons to the action bar, one for a searchFilter and one for a file picker, both icons are white. File picker icon (at the right) looks good, but somehow search icon looks dark grey. When typing on the search text view, close button also looks dark grey.
I've tried changing color of the actionbar and also from the searchview, without success. Why is the search view showing this color? How can I change it?
Thank you very much.
UPDATE: I thought that my app was using my icon but it doesn't, it uses the default search view icon, so my question actually is, how do I change the default icon of the search view?
This sentence at the menu.xml file is not working:
android:icon="#drawable/selectable_header_search"
Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. See this answer for details.
However, I think that your problem is caused by inheriting from the wrong theme. Please use android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on the action bar should have a light color.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
...
</style>
Since the searchViewSearchIcon attribute is not public, you can change the icon using the following code:
int searchIconId = searchView.getContext().getResources().getIdentifier("android:id/search_button",null, null);
ImageView searchIcon = (ImageView) searchView.findViewById(searchIconId);
searchIcon.setImageResource(R.drawable........);
Try to set up in the showAsAction this option: *MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW*
Without this option the SearchView do not take the icon which you setup for action button.
menu.add("Search")
.setIcon(
getResources().getDrawable(
R.drawable.selectable_header_search))
.setActionView(searchView)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
The easiest way I've found to change the default searchview icon in the action bar is in your onPrepareOptionsMenu. You can see my answer here to a similar question!
In your theme style include this:
<style name="YourTheme.Toolbar">
<item name="searchViewStyle">#style/YourActionBarSearch</item>
<item name="editTextColor">#color/your_ab_text_color</item>
<item name="android:textColorHint">#color/your_ab_hint_color</item>
</style>
You can now define the style of the SearchView with searchViewStyle, and editTextColor will set the color of the text in the search box. By setting android:textColorHint you will also set the color of the hint, e.g. "Search...".
<style name="YourActionBarSearch" parent="#style/Widget.Holo.SearchView">
<item name="searchIcon">#drawable/ic_ab_search</item>
<item name="queryBackground">#null</item>
<item name="submitBackground">#null</item>
<item name="searchHintIcon">#drawable/ic_ab_small_search</item>
<item name="defaultQueryHint">#string/toolbar_search_hint</item>
<item name="closeIcon">#drawable/ic_ab_small_search_close</item>
</style>
This will style your search view as you like, more or less. The field searchIcon is the icon in the action bar. The field searchHintIcon is the small icon to the left of the hint in the search field. The field closeIcon is the close icon at the right side of the search field.
Check this out, for more style settings:
$ANDROID_SDK/platforms/android-24/data/res/values/styles_holo.xml
For those like me hoping to find a way to truly change the icon, you can use this with actionbar sherlock:
// Getting the 'search_icon'
ImageView searchIcon = (ImageView)searchView.findViewById(R.id.abs__search_button);
// Setting background of 'search_plate' to earlier defined drawable.
searchIcon.setImageResource(R.drawable.search_button_selector);
You can't change the default one with the common way android:icon, because the field related to it had been set to private.
I added the action bar tabs programmatically. I do not know how to align the action bar tabs to the right.
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// instantiate tabs
ActionBar.Tab pageTab= bar.newTab().setText(getString(R.string.page))
.setIcon(R.drawable.ic_page);
bar.addTab(pageTab);
// other settings
bar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
bar.setDisplayShowHomeEnabled(true);
// remove the activity title to make space for tabs
bar.setDisplayShowTitleEnabled(false);
Action bar tabs appear on the left. The right is used for your options menu and any items from it that you promote to be toolbar buttons.
This has been a while since the original question, but... I needed a solution for the same problem due to visual appearance of the Activity. It turns out that if you append white spaces to either the title or subtitle, the tabs will be moved to the right, so you can do this:
bar.setTitle("Some titile\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
This will shift the whole tab bar to accommodate the space for the white spaces. I must say that this is not an elegant solution but works if you don't have any actions in the action bar. (I didn't check what happens when actions are present.)
I was able to align the actionbar right by customizing my application theme
In my AndroidManifest.xml, I added a android:theme property:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/CustomActionBarTheme">
...
I then added a new themes.xml file to my project, and added :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabBarStyle">#style/MyActionBarTabBar</item>
</style>
<style name="MyActionBarTabBar">
<item name="android:gravity">right</item>
</style>
</resources>
The tabs should now be right aligned.
EDIT:
It works only if your actionbar is displayed on 2 lines (in portrait orientation)