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"
Related
I'm trying to customize Toolbar's popup menu. Now I can not set background color of menu item.
My styles.xml looks like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text_color</item>
<item name="android:dropDownListViewStyle">#style/AppTheme.DropDown</item>
<item name="android:itemTextAppearance">#style/menuItemColor</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text_color</item>
<item name="dropDownListViewStyle">#style/AppTheme.DropDown</item>
<item name="itemTextAppearance">#style/menuItemColor</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">\
<item name="titleTextColor">#color/actionbar_text_color</item>
<item name="subtitleTextColor">#color/actionbar_text_color</item>
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
<style name="AppTheme.DropDown" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:background">#color/background_color</item>
<!-- Support library compatibility -->
<item name="background">#color/background_color</item>
</style>
<style name="menuItemColor">
<item name="android:textColor">#color/inactive_text_color</item>
</style>
</resources>
I added ActionBar to activity layout with code
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/AppTheme.ActionBar"/>
Note: I'm using AppCompat, not Holo or other.
This may help you,create a style like,
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
and add it to your main themes..
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item> <! added it here
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text_color</item>
<item name="android:textColor">#color/text_color</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text_color</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">\
<item name="titleTextColor">#color/actionbar_text_color</item>
<item name="subtitleTextColor">#color/actionbar_text_color</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item> <! added it here
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
You have to define style for Overflow Menu too like this :
<!-- OverFlow menu Styles -->
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#color/sp_red_500</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:background">#color/white</item>
</style>
and in your parent theme style( Base application theme.) define drop down menu style like this :
<item name="dropDownListViewStyle">#style/PopupMenuListView</item>
I'd like to create app with setTitle function at ActionBar
But, some strings are bigger than ActionBar width, and i want use autoscrollable function for my title.
I try to create style for my ActionBar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_background</item>
<item name="android:titleTextStyle">#style/ActionBarTitleStyle</item>
<!-- Support library compatibility -->
<item name="background">#drawable/ab_background</item>
<item name="titleTextStyle">#style/ActionBarTitleStyle</item>
</style>
<style name="ActionBarTitleStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">1</item>
<item name="android:singleLine">true</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:textColor">#FF64A3</item>
</style>
But it doesn't work.
Please tell me what i do wrong?
I tried to set theme at run time, other than action bar everything works fine.
I am setting theme in oncreate() before super.oncreate(...)
How to set theme in action bar ?
This is my theme in style.xml
<style name="abcThemeTest" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#color/RED</item>
<item name="actionBarStyle">#style/MyActionBarTest</item>
</style>
<style name="MyActionBarTest" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#color/RED</item>
<item name="android:background">#color/RED</item>
<item name="titleTextStyle">#style/MyActionBarTitleTextTest</item>
</style>
<style name="MyActionBarTitleTextTest" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/WHITE</item>
<item name="android:textStyle">bold</item>
</style>
Simply Modify your style file like this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<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/actionbar_text</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">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
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>
I am using support library to add an action bar.
in res/values/styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Translucent</item>
<item name="android:windowBackground">#drawable/transparent_background</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<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/actionbar_text</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">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
and then when i add this
application android:theme="#style/CustomActionBarTheme"
to mainfest, the application falls to start. if i removed it the application works perfectly
help pelase
Try using: Action bar stylle generator. It's simple and works perfectly for default, ActionBarSherlock, Holoeverywhere themes.