I want to to customize my app and i've applied a theme but the options menu doesn't seem to apply my theme.
I want my text color to be white, my background to be black and the highlighted/selected menu item to be yellow.
Here is my theme.xml:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/application_color5</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="android:selectableItemBackground">#drawable/icone_barratopo_selector</item>
<item name="android:actionBarItemBackground">#drawable/icone_barratopo_selector</item>
<item name="android:selectableItemBackground">#drawable/icone_barratopo_selector</item>
<!-- Panel attributes -->
<!-- <item name="android:panelBackground">#drawable/selectable_background</item> --
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/application_color5</item>
<item name="actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="selectableItemBackground">#drawable/icone_barratopo_selector</item>
<item name="actionBarItemBackground">#drawable/icone_barratopo_selector</item>
<item name="selectableItemBackground">#drawable/icone_barratopo_selector</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/background_barratopo_superior</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="background">#drawable/background_barratopo_superior</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/application_color2</item>
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#drawable/tab_text_selector</item>
</style>
<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">#drawable/actionbar_tab_indicator</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_tab_indicator</item>
</style>
My menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motobox="http://schemas.android.com/apk/res-auto" >
<!--
<item
android:id="#+id/option_availability"
android:icon="#drawable/icone_barratopo_mymotobox"
android:orderInCategory="100"
motobox:showAsAction="always"/>
-->
<item
android:id="#+id/option_refresh"
android:icon="#drawable/icone_barratopo_back"
android:orderInCategory="100"
motobox:showAsAction="always"/>
<item
android:id="#+id/status"
android:orderInCategory="100"
android:title="Indisponível"
motobox:showAsAction="never"/>
<item
android:id="#+id/logout"
android:orderInCategory="100"
android:title="Logout"
motobox:showAsAction="never"/>
and my selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/application_color3" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<!-- Pressed -->
<item android:drawable="#color/application_color2" android:state_pressed="true"/>
<!-- Focused -->
<item android:drawable="#color/application_color2" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
Rename your file from theme.xml to
res/values/themes.xml
And remember you can apply your theme to your entire app
<application android:theme="#style/myCustomTheme">
or individual activities
<activity android:theme="#android:style/myCustomTheme">
Edit the line:
<item name="background">#drawable/actionbar_tab_indicator</item>
to
<item name="android:background">#drawable/actionbar_tab_indicator</item>
:)
Related
I try to set the title text on my DialogFragment but its not working as I expected. The only thing that works is if I in the onCreate() of the dialogFragment explicitly do like this:
setStyle(DialogFragment.STYLE_NORMAL, MyStyl...............);
and in that style I have set the
<item name="android:windowNoTitle">false</item>
But I have multiple themes that user can change to during run time so I do like this to set DialogFragment theme.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:srcCompat="http://schemas.android.com/tools"
android:id="#+id/place_search_dialog"
style="?alertDialogTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
But now the Title text is not showing even do I in the alertDialogTheme attribute have set the "android:windowNoTitle">false</item>,
why is this happening?
<resources >
<!-- Base Theme -->
<style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Attributes for all APIs -->
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
<item name="dialogTheme">#style/AppTheme.Dialog</item>
<item name="alertDialogTheme">#style/AppTheme.Dialog.Alert</item>
<!-- Theme for the Preferences -->
<item name="preferenceTheme">#style/AppPreferenceTheme</item>
</style>
<!-- Default App Theme -->
<style name="AppTheme" parent="BaseTheme">
<!-- API specific attributes 14+ -->
<item name="selectableRectDrawable">#drawable/state_list_selectable_rect_black</item>
<item name="selectableRectDrawableInverse">#drawable/state_list_selectable_rect_white</item>
<item name="selectableRectDrawableColored">#drawable/state_list_selectable_rect_black</item>
<item name="selectableRoundedRectDrawable">#drawable/state_list_selectable_rounded_rect_black</item>
<item name="selectableRoundedRectDrawableInverse">#drawable/state_list_selectable_rounded_rect_white</item>
<item name="selectableRoundedRectDrawableColored">#drawable/state_list_selectable_rounded_rect_black</item>
</style>
<!-- Bohemia App Theme -->
<style name="BaseTheme.Bohemia" parent="AppTheme">
<!-- Attributes for all APIs -->
<item name="colorPrimary">#color/material_bohemia_400</item>
<item name="colorPrimaryDark">#color/material_bohemia_600</item>
<item name="colorAccent">#color/material_bohemia_a100</item>
<item name="dialogTheme">#style/AppTheme.Dialog.Bohemia</item>
<item name="alertDialogTheme">#style/AppTheme.Dialog.Alert.Bohemia</item>
<item name="android:windowBackground">#color/material_bohemia_300</item>
<item name="colorControlHighlight">#color/material_bohemia_a100</item>
<item name="colorControlActivated">#color/material_bohemia_a100</item>
<item name="colorControlNormal">#color/material_bohemia_a200</item>
</style>
<style name="AppTheme.Bohemia" parent="BaseTheme.Bohemia">
<!-- API specific attributes 14+ -->
<item name="selectableRectDrawableColored">#drawable/state_list_selectable_rect_bohemia</item>
<item name="selectableRoundedRectDrawableColored">#drawable/state_list_selectable_rounded_rect_bohemia</item>
</style>
<!-- Red App Theme -->
<style name="BaseTheme.Red" parent="AppTheme">
<!-- Attributes for all APIs -->
<item name="colorPrimary">#color/material_red_500</item>
<item name="colorPrimaryDark">#color/material_red_700</item>
<item name="colorAccent">#color/material_red_a700</item>
<item name="dialogTheme">#style/AppTheme.Dialog.Red</item>
<item name="alertDialogTheme">#style/AppTheme.Dialog.Alert.Red</item>
<item name="android:windowBackground">#color/material_red_300</item>
<item name="colorControlHighlight">#color/material_red_a200</item>
<item name="colorControlActivated">#color/material_red_a200</item>
<item name="colorControlNormal">#color/material_red_a200</item>
<!-- Chat color -->
</style>
<style name="AppTheme.Red" parent="BaseTheme.Red">
<!-- API specific attributes 14+ -->
<item name="selectableRectDrawableColored">#drawable/state_list_selectable_rect_red</item>
<item name="selectableRoundedRectDrawableColored">#drawable/state_list_selectable_rounded_rect_red</item>
</style>
<!-- Orange App Theme -->
<style name="BaseTheme.Orange" parent="AppTheme">
<!-- Attributes for all APIs -->
<item name="colorPrimary">#color/material_orange_500</item>
<item name="colorPrimaryDark">#color/material_orange_700</item>
<item name="colorAccent">#color/material_orange_a700</item>
<item name="dialogTheme">#style/AppTheme.Dialog.Orange</item>
<item name="alertDialogTheme">#style/AppTheme.Dialog.Alert.Orange</item>
<item name="android:windowBackground">#color/material_orange_300</item>
<item name="colorControlHighlight">#color/material_orange_a200</item>
<item name="colorControlActivated">#color/material_orange_a200</item>
<item name="colorControlNormal">#color/material_orange_a200</item>
</style>
<style name="AppTheme.Orange" parent="BaseTheme.Orange">
<!-- API specific attributes 14+ -->
<item name="selectableRectDrawableColored">#drawable/state_list_selectable_rect_orange</item>
<item name="selectableRoundedRectDrawableColored">#drawable/state_list_selectable_rounded_rect_orange</item>
</style>
<!-- Default Dialog Theme -->
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
</style>
<!-- Bohemia Dialog Theme -->
<style name="AppTheme.Dialog.Bohemia">
<item name="colorPrimary">#color/material_bohemia_400</item>
<item name="colorPrimaryDark">#color/material_bohemia_500</item>
<item name="colorAccent">#color/material_bohemia_a100</item>
</style>
<!-- Red Dialog Theme -->
<style name="AppTheme.Dialog.Red">
<item name="colorPrimary">#color/material_red_500</item>
<item name="colorPrimaryDark">#color/material_red_700</item>
<item name="colorAccent">#color/material_red_a700</item>
</style>
<!-- Orange Dialog Theme -->
<style name="AppTheme.Dialog.Orange">
<item name="colorPrimary">#color/material_orange_500</item>
<item name="colorPrimaryDark">#color/material_orange_700</item>
<item name="colorAccent">#color/material_orange_a700</item>
</style>
<!-- Default Alert Dialog Theme -->
<style name="AppTheme.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowNoTitle">false</item>
</style>
<!-- Bohemia Alert Dialog Theme -->
<style name="AppTheme.Dialog.Alert.Bohemia" >
<item name="colorPrimary">#color/material_bohemia_400</item>
<item name="colorPrimaryDark">#color/material_bohemia_500</item>
<item name="colorAccent">#color/material_bohemia_a100</item>
<item name="android:background">#color/material_bohemia_400</item>
<item name="android:textColor">#color/material_bohemia_a200</item>
</style>
<!-- Red Alert Dialog Theme -->
<style name="AppTheme.Dialog.Alert.Red">
<item name="colorPrimary">#color/material_red_500</item>
<item name="colorPrimaryDark">#color/material_red_700</item>
<item name="colorAccent">#color/material_red_a700</item>
<item name="android:background">#color/material_red_500</item>
</style>
<!-- Orange Alert Dialog Theme -->
<style name="AppTheme.Dialog.Alert.Orange">
<item name="colorPrimary">#color/material_orange_500</item>
<item name="colorPrimaryDark">#color/material_orange_700</item>
<item name="colorAccent">#color/material_orange_a700</item>
<item name="android:background">#color/material_orange_500</item>
</style>
</resources>
I ended up creating custom title and simply not call setTitle() on the dialog
I already setup my tabhost background colour but it's not working.
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
</style>
<style name="ActionBarTabStyle"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_bg_selector</item>
<item name="background">#drawable/tab_bg_selector</item>
</style>
tab_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/blueLight" android:state_pressed="true"/>
<item android:drawable="#color/blueLight" android:state_selected="true"/>
<item android:drawable="#color/blueDark"/>
</selector>
bottom_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
Since you are using AppCompat library, use this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
</style>
<style name="ActionBarTabStyle"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_bg_selector</item>
<item name="background">#drawable/tab_bg_selector</item>
</style>
You needed the Widget.AppCompat.ActionBar.TabView parent and the android: variants for AppCompat support.
That is according to ActionBar's documentation and ActionBar Tab's documentation.
If you are OK to change color in code than you can try this:
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String arg0) {
for (int i = 0; i < tab.getTabWidget().getChildCount(); i++) {
tab.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.tab_selected); // unselected
}
tab.getTabWidget().getChildAt(tab.getCurrentTab())
.setBackgroundResource(R.drawable.tab_unselected); // selected
}
});
You can try it:
tab_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:drawable="#drawable/unselected_tab" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/button_buynow" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="#drawable/unselected_tab" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/selected_tab" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
<!-- Pressed -->
<!-- Non focused states -->
<item android:drawable="#drawable/unselected_tab" android:state_focused="false" android:state_pressed="true" android:state_selected="false"/>
<item android:drawable="#drawable/button_buynow" android:state_focused="false" android:state_pressed="true" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="#drawable/unselected_tab" android:state_focused="true" android:state_pressed="true" android:state_selected="false"/>
<item android:drawable="#drawable/button_buynow" android:state_focused="true" android:state_pressed="true" android:state_selected="true"/>
</selector>
After declaration in you MainActivity, you can use following code:
TabWidget widget = th.getTabWidget();
for (int i = 0; i < widget.getChildCount(); i++) {
View v = widget.getChildAt(i);
v.setBackgroundResource(R.drawable.tab_selector);
}
In your theme, add the following
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
Then add MyActionBar style (replace drawable entries with your own):
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- action bar background -->
<item name="background">#drawable/ab_solid_mytabhost</item>
<!-- needed for 'stacked' & 'split' action bar (used by tabhost) -->
<item name="backgroundStacked">#drawable/ab_stacked_solid_mytabhost</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_mytabhost</item>
</style>
Your styles.xml should look something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
</style>
<style name="ActionBarTabStyle" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_bg_selector</item>
<item name="background">#drawable/tab_bg_selector</item>
<!-- add these -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- add this-->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- action bar background -->
<item name="background">#drawable/ab_solid_mytabhost</item>
<!-- needed for 'stacked' & 'split' action bar (used by tabhost) -->
<item name="backgroundStacked">#drawable/ab_stacked_solid_mytabhost</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_mytabhost</item>
</style>
For a working sample, here's a link to a sample project: https://github.com/ebernie/MyTabHostThemeSample
I use the code below to change the style of a tabbed activity in my application:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
<!-- Action Bar them -->
<style name="ActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_appolo</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_appolo</item>
<item name="titleTextStyle">#style/ActionBarText</item>
<item name="icon">#drawable/ic_action_launcher</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Appolo</item>
</style>
<style name="ActionBarText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ActionBarTabStyle.Appolo" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="background">#drawable/actionbar_tab_indicator</item>
</style>
This is the actionbar_tab_indicator content:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="#android:color/transparent" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/tab_unselected_focused" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_selected_focused" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/tab_unselected_pressed" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_selected_pressed" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/tab_unselected_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_selected_pressed" />
</selector>
I also use the code below for styles in style-v11 and style-v14:
...
<style name="ActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_appolo</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_appolo</item>
<item name="android:titleTextStyle">#style/ActionBarText</item>
<item name="android:icon">#drawable/ic_action_launcher</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Appolo</item>
</style>
<style name="ActionBarText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ActionBarTabStyle.Appolo" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/actionbar_tab_indicator</item>
</style>
...
But it is not changing the style of the tab bar.
I checked my code many times, I searched and reviewed all my notes but I can't find what the problem is. Does anyone have any answers?
The problem was in this part of code:
<style name="ActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_appolo</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_appolo</item>
<item name="titleTextStyle">#style/ActionBarText</item>
<item name="icon">#drawable/ic_action_launcher</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Appolo</item>
and especially this line:
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Appolo</item>
this line should not be in the custom them that I want to use as my action bar theme. The right way is adding this under my custom app them so I remove this line from above part and add it under AppBaseTheme:
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">#style/ActionBarTheme</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Appolo</item>
</style>
and now the code is working right.
Write this in your style xml file.
<item name="actionBarTabStyle">#style/CustomActionBarTabs </item>
<style name="CustomActionBarTabs"parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_custom_actionbar_style</item>
<item name="android:textColor">#666666</item>
</style>
Try this:
<style name="ActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarTheme.ActionBarStyle</item>
</style>
<style name="ActionBarTheme.ActionBarStlye" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_solid_appolo</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_appolo</item>
<item name="android:titleTextStyle">#style/ActionBarTheme.ActionBar.TitleTextStyle</item>
<item name="android:icon">#drawable/ic_action_launcher</item>
<item name="android:actionBarTabStyle">#style/ActionBarTheme.ActionBar.TabStyle</item>
</style>
<style name="ActionBarTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ActionBarTheme.ActionBar.TabStyle" parent="#style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_tab_indicator</item>
</style>
Also make sure you're using your theme in the AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme" >
I have noticed, with older versions of Android, the app crashes if the Theme is not a child of AppCompat. This should be a work around.
EDIT: you also forgot to put android: before background, icon, etc.
Make sure that You have applied app-theme in manifest file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme"
android:uiOptions="splitActionBarWhenNarrow" >
This is my menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.citrusz.MainActivity" >
<item
android:id="#+id/action_offers"
android:showAsAction="ifRoom"
android:title="#string/captain_offers"/>
<item
android:id="#+id/action_events"
android:showAsAction="ifRoom"
android:title="#string/events_list"/>
<item
android:id="#+id/action_user"
android:icon="#drawable/ic_launcher"
android:showAsAction="always"
android:title="#string/action_user"/>
And this is my ActionBar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="background">#drawable/actionbar_background</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
And I getting following output, I need Logout should be visible in ActionBar.
Try changing this
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
To
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
This is my main.xml in menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:themomotrail="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_login"
android:orderInCategory="100"
android:title="Login"
themomotrail:showAsAction="ifRoom"/>
</menu>
This is my theme.xml
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- <item name="android:actionBarStyle">#style/MyActionBar</item> -->
<!-- Support library compatibility -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/action_bar</item>
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/tab_bar_background</item>
<item name="android:gravity">center</item>
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<!-- ActionBar styles -->
<style name="ActionBarTabBar" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_bar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/tab_bar_background</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textSize">15sp</item>
<item name="android:padding">5dip</item>
</style>
I'm using this custom theme for the application. The problem here is, the menu item always appears in the overflow menu instead of appearing in the actionbar. What am I doing wrong ? Thanks
In the menu xml, the themomotrail namespace is wrong
You have:
xmlns:themomotrail="http://schemas.android.com/apk/res/android"
It should be:
xmlns:themomotrail="http://schemas.android.com/apk/res-auto"