am creating an action bar using Android API level 21, lollipop, and I've got to the point where I have to add a text button in the actionbar, I've added it successfully, but the text says: "SUBMIT" I want it to show "Submit".
Any ideas ? I've tried fiddling around with the styles with no luck here's my code:
<style name="myStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textSize">17sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">false</item>
</style>
Important: This will only work on API 14+ as textAllCaps was introduced in API 14.
In your API 14+ style specify this:
<item name="android:actionMenuTextAppearance">#style/TextAppearance.MyApp.Widget.ActionBar.Menu</item>
Then define the actual font style derived from appropriate parent.
<style name="TextAppearance.MyApp.Widget.ActionBar.Menu" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
If you don't use appcompat-v7 library replace AppCompat parent with Holo on API 14+ and Material on API 21+ (and prefixing the style with android:). Ie:
<style name="TextAppearance.MyApp.Widget.ActionBar.Menu" parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
Tested on Kitkat.
Pre-ICS
I am not able to test it but you might want to try. Please report the result.
In your pre-API 14 theme specify
<item name="actionMenuTextAppearance">#style/TextAppearance.MyApp.Widget.ActionBar.Menu</item>
Add the following to the action bar menu style:
<item name="textAllCaps">false</item>
Related
I am really getting crazy! I set in styles.xml and styles-v21.xml the attrs colorPrimaryDark and android:colorPrimaryDark but my statusBar does not change the color. I am using AppCompat-v22. Any idea?
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/brand_color</item>
<item name="colorPrimaryDark">#color/brand_color_dark</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="colorControlNormal">#color/brand_color</item>
<item name="colorControlActivated">#color/brand_color</item>
<item name="colorControlHighlight">#color/brand_color</item>
<item name="android:seekBarStyle">#style/SeekBarAppTheme</item>
<item name="android:windowAnimationStyle">#style/activity_animations</item>
</style>
styles-v21.xml:
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:colorPrimary">#color/brand_color</item>
<item name="android:colorPrimaryDark">#color/brand_color_dark</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
try add android:fitsSystemWindows="true" on your layout xml's root view
I have tried on device > API 21 device and found this attributes is necessary if you want change statusbar color
Your status bar color can only change in API 21+. In older devices, Android doesn't allow the developer to touch that attribute. Read this article, in Theming part:
When you set these attributes, AppCompat automatically propagates their values to the framework attributes on API 21+. This automatically colors the status bar and Overview (Recents) task entry.
On older platforms, AppCompat emulates the color theming where
possible. At the moment this is limited to coloring the action bar and
some widgets.
Hence, I think you tested with device < API 21, you should try with newer OS device.
just change your targetSdkVersion to 23
I need to change text size of action buttons in AppBar/Toolbar. It should be 14sp, but I'll use 20sp in this example, because it is more evident. I am using appcompat-v7 22.1.1
At first I tried to use theme attribute android:actionButtonStyle:
<style name="FirstAttemptTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionButtonStyle">#style/Custom.Widget.AppCompat.Light.ActionButton</item>
</style>
<style name="Custom.Widget.AppCompat.Light.ActionButton" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:textSize">20sp</item>
</style>
Then I ran application on the Lollipop and the result was as needed:
But then I used an emulator with lower version and my theming had no effect:
I digged a little deeper and discovered that abc_action_menu_item_layout.xml is used for action menu items and it has a line android:textAppearance="?attr/actionMenuTextAppearance"
So I tried to modify this theme attribute (I also had to add textStyle:bold):
<style name="SecondAttemptTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu</item>
</style>
<style name="Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
</style>
As in the first time, the result was as needed on Lollipop and no effect on any version below.
So, the question is: how to properly change text size for action menu item?
PS: I created a simple project on github to demostrate my issue
It appears that actionButtonStyle and actionMenuTextAppearance should be used without android: namespace.
As it can be seen in values-v21/values.xml of support library, Lollipop uses attribute from system theme (note the android: prefix), that's why my attempts worked with it:
<style name="Base.V21.Theme.AppCompat.Light" parent="Base.V7.Theme.AppCompat.Light">
...
<item name="actionButtonStyle">?android:attr/actionButtonStyle</item>
...
</style>
I am using the Action Bar support library (appcompat v7), my app is set to a minimum api of 7, and a target of 21.
I have two styles files, a base one, and one targeted at devices api 11+.
When running the app on a device running KitKat, it seems that android:actionBarStyle is ignored, leaving the action bar styled as default (#style/Widget.AppCompat.ActionBar.Solid), instead of applying the given background.
But if I remove my v11 styles/comment them out, KitKat listens to the actionBarStyle attribute set in the base styles.xml file and sets my custom background without any problems.
So my question, where am I going wrong with the v11 styles?
From what I understand, according to the android docs, you are supposed to supply the additional styles for devices running 11+ using the android: prefix, but this just doesn't seem to be working for me.
Stripped down, this is my /res/values/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#drawable/ab_solid_</item>
</style>
and this is my /res/values-v11/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_</item>
</style>
as you can see, the only difference between the two is the use of the android: prefix.
According to the official doc, with the new AppCompat-v21, you can remove all of values-v14+ Action Bar styles and use only one theme declaration, in values:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
I am defining action bar styles for an Android device running 4.4.2. I've tested the styles on a device running 4.3 and they work prefectly. The phone running KitKat however refuses to apply any of the rules defined by the style. I've defined the same theme in all three folders: values, values-11 and values-14.
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/oc_actionbar_background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
<item name="android:displayOptions">showHome</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
I've also added
android:theme="#style/AppTheme"
to the manifest application tag. But the styles are still not applied. I have however managed to change the action bar properties at runtime (changing the color), but that's not a desirable way of handling such problems.
If anyone could advise me on the matter, I would be most grateful.
To prevent these kind of issues, I like to use the following tool to generate the style for me: http://jgilfelt.github.io/android-actionbarstylegenerator/
Easy to use tool that generates the style just like I want it. Might help you too, since you avoid these issues. Just paste this in your project, and you're done.
Other tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html
I have the problem to customize the back arrow. I want a red arrow instead of default arrow. I've read many topics about that but it doesn't work.
So i place my styles in res/values/styles.xml. Here is my code :
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="homeAsUpIndicator">#drawable/btn_nav_retour</item>
</style>
I can't set "android:homeAsUpIndicator" beacause it requires api level 11 and my min sdk is 9.
Should I set the same code in res/values-v11/styles.xml ?
Thx
To work in all API's you should create style.xml in values-v11 and values-v14 folder. In values-v14 for example you should use:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/btn_nav_retour</item>
</style>
In default values folder you should use attributes given by ActionBarSherlock, but for higher API levels you should stick with Android default ActionBar attributes and place android: in front of them. In that way it will work for higher API levels.
As a sidenote to the accepted answer:
if you don't want to duplicate your Theme for both API-ranges, you could add both items to your AppBaseTheme in values/styles.xml:
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="homeAsUpIndicator">#drawable/btn_nav_retour</item>
<item name="android:homeAsUpIndicator" tools:targetApi="11">#drawable/btn_nav_retour</item>
</style>
The targetApi-attribute prevents the error-message from lint. The xml-item it annotates is ignored by older Android-versions.