Change ActionBar Tabs background color - android-actionbar

Is there a way to change the background color of the tab bar in the ActionBar without changing it in the one line version?
To clarify what I want: In portrait mode the ActionBar is split in two lines, the ActionBar itself and the tabs below. In landscape mode the tabs are in the actual ActionBar.
I want to change the background color of the portrait mode. If I change the background in the TabView it'll be changed for both modes. Do I have to create separate styles for those? Which brings up a second question: is there a way to know when it'll be two lines and when not?
Or am I just missing something?
I'm using ActionBarSherlock btw

I think you are looking for the android:backgroundStacked attribute of the ActionBar style:
<style name="MyTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:backgroundStacked">#drawable/my_stacked_background</item>
</style>
or (If using ActionBarSherlock):
<style name="MyTheme" parent="#style/Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:backgroundStacked">#drawable/my_stacked_background</item>
<item name="backgroundStacked">#drawable/my_stacked_background</item>
</style>

To Change Actionbar Tab's color, Pls use this code:
//For Example if you want White color as Tabs background, then
getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));

In ActionBarSherlock's values/abs__themes.xml there is
<item name="actionModeSplitBackground">#drawable/abs__cab_background_bottom_holo_dark</item>
You have to create your own theme derived from ABS
<style name="AppTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
<item name="actionModeSplitBackground">#drawable/my_split_background</item>
</style>
Hope this helps you.

ColorDrawable colorDrawable = new ColorDrawable(Color.White);
actionBar.SetStackedBackgroundDrawable(colorDrawable);
for xamarin folks.

To seperate styles depending on orientation you have to create in your /res folder a new folder called layout-land (for landscape mode) and layout-port (in portrait mode) and put your xml files for action bar and set it's specific style (with the color you want) on each folder.

Related

Change Context Action Bar checkmark/done drawable?

Is there a good way to change the Context Action Bar checkmark drawable without creating a custom view for the whole Action Bar?
Yes there is. You simply need to add the "actionModeCloseDrawable" item to your style.
<style name="MyCustomTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionModeCloseDrawable">#drawable/my_custom_close_icon</item>
<!-- Support library compatibility -->
<item name="actionModeCloseDrawable">#drawable/my_custom_close_icon</item>
</style>

selector for actionBarItemBackground not working

I have to following problem, I want to change the selector from the actionbar item (just the normal actionbar, neither support actionbar nor actionbarsherlock). The backgroud color should be grey instead of default blue if the item icon is pressed. I have searched a lot and know that I need to override the attribute android:actionBarItemBackground in styles, but still my selector doesnt work, the background color is transparent, but the color in on pressed state is not grey, it stays transparent. :/
here is my code:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarItemBackground">#drawable/action_bar_item_drawable</item>
</style>
and here the drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:drawable="#android:color/transparent"/>
<item android:drawable="#color/grey" android:state_pressed="true"/>
</selector>
anyone an idea?
When you supply a selector as a drawable, the first matching item that satisfies all conditions will be displayed.
In your drawable, the transparent color gets chosen every time because it doesn't have any condition such as state_pressed="true".
You should put items with more restricting conditions first and item without any condition as the last one.
Your drawable should instead look like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:drawable="#color/grey" android:state_pressed="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>

ActionBar with Search and One more option

I would like to add 2 menu options to the action bar. One is Search and the other is custom one. When I tried to add, the 2nd option is always going to over flow menu only. But I want that to be displayed always as below.
But it's being displayed as
Here is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_search"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_search"
android:title="#string/action_search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
android:showAsAction="ifRoom|withText"
android:title="#string/action_add_new_event"/>
</menu>
Any idea about how can I achieve this? Thanks in advance.
I just modified the below code
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
android:showAsAction="ifRoom|withText"
android:title="#string/action_add_new_event"/>
to
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
yourapp:showAsAction**="ifRoom|withText"
android:title="#string/action_add_new_event"/>
and it worked.

How to customize ActionBar in Android (ActionbarSherlock)?

I have used ActionBarSherlock in my application for providing ActionBars to pre honeycomb devices. I want to use Light.DarkActionBar Theme in, How can I customize following for parts of the ActionBar (see image)
Background color of ActionBar
Background Image for ActionBar tab bar
The bottom line which represents the selected tab
The divider between tabs...
I have tried using following settings, Though I have achieved some success but the result however doesn't look as expected,
<item name="android:background">#drawable/bg_title_bar</item>
<item name="background">#drawable/bg_title_bar</item>
<item name="actionModeSplitBackground">#drawable/bg_tab_bar</item>
<item name="android:actionModeSplitBackground">#drawable/bg_tab_bar</item>
Which are the other settings that I should use ? Thanks!!
This is how I did it just in case someone has similar requirements in future..
I downloaded a sample zip file from Style Genarator... Unzipping and a close look on the content suggested that I needed following attributes,
for Background color of ActionBar
<item name="background">#drawable/title_bg</item>
<item name="android:background">#drawable/title_bg</item>
2.
for Background Image for ActionBar tab bar
<item name="backgroundStacked">#drawable/tab_bg</item>
<item name="android:backgroundStacked">#drawable/tab_bg</item>
3.
for The bottom line which represents the selected tab
i. I created a style as follows
<style name="ActionBar.TabStyle" parent="#style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="background">#drawable/ab_tab_indicator</item>
<item name="android:background">#drawable/ab_tab_indicator</item>
</style>
ii. I used that style in the theme as follows
<item name="actionBarTabStyle">#style/ActionBar.TabStyle</item>
<item name="android:actionBarTabStyle">#style/ActionBar.TabStyle</item>
4 for The divider between tabs...
in theme I added two lines..
<item name="actionBarTabBarStyle">#style/My.ActionBar.TabBar</item>
<item name="android:actionBarTabBarStyle">#style/My.ActionBar.TabBar</item>
than
<style name="My.ActionBar.TabBar" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="divider">#drawable/tab_divider</item>
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/tab_divider</item>
<item name="android:dividerHeight">24dp</item>
<item name="android:dividerPadding">8dp</item>
<!-- <item name="android:background">#drawable/tab_unselected</item> -->
</style>
Here is a link! use this style generator, customize as you need. Download the file, copy past all the drawables to respective directories, copy style.xml under values directory..
and use the give theme name as your theme either in manifest of respective activity..
Hope this works for you

How do I change CFCHART title font?

I am using the WebCharts3D interface to create and modify charts, and then using the generated XML style as an in-line style in my Coldfusion code.
So this shows up correctly in the WebCharts3D:
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
This simply shows the example title with no box around it, and set to the desired font size and weight. You can take this code, copy it into the WebCharts "XML Style" window, apply it, and see that it works.
I use this in my Coldfusion code like this:
<cfsavecontent variable="piecontent">
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
</cfsavecontent>
<cfchart name="mychart" format="png"
style="#piecontent#">
<cfchartseries type= "pie">
<cfchartdata item="sample1" value="10">
<cfchartdata item="sample2" value="20">
</cfchartseries>
</cfchart>
The title correctly has "decoration" set to "none", because there is no box around it, but the title font size and weight is totally ignored. Is this a bug? Is there a workaround?
EDIT: It appears that this problem of ignored font size and weight is ALSO true for the overall font, like if you put this: <pieChart depth="Double" style="Solid" font="Arial-16-Bold">.
It seems like those particular settings are ignored in favor of the cfchart tag's font attributes. Try using those instead:
<cfchart format="png" font="Arial" fontBold="true" fontSize="18">
EDIT: While the above works with pie charts (only), it seems like another bug... What does work is interfacing with webcharts directly. It is more involved, but offers complete control over chart settings.
My experience, though I can't find any proof online other than my own testing, is that ColdFusion's implementation of Webcharts does not support styling the title.