Make ActionBar title uppercase - android

How do I make the ActionBar title uppercase? Some answers suggest putting <item name="android:textAllCaps">true</item> but this has no effect when I put it in the actionBar style or actionBar's titleTextStyle. It only has an effect when I put in in the AppTheme style but that makes a bunch of things in my app also in all caps which I don't want.
My styles:
<style name="AppTheme" parent="AppBaseTheme">
<!-- snip snip -->
<item name="android:actionBarStyle">#style/NewActionBar</item>
</style>
<style name="NewActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/text_pink</item> <!-- no effect -->
<item name="android:titleTextStyle">#style/NewActionBarTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
<style name="NewActionBarTitle">
<item name="android:textSize">#dimen/tiny_text_size</item> <!-- no effect -->
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
And why do the NewActionBar and NewActionBarTitle styles appear to have no effect no matter what I put in them? Is there something wrong with my styles or my action bar or what?
Edit: I've just deleted entirely the styles NewActionBar and NewActionBarTitle (and the reference to them in the AppTheme style) and the action bar looks completely the same. So something is broken. What could it be?

You need to set android:textAllCaps="true" on the text appearance for the action bar's title, rather than the action bar style itself or on your base activity theme.
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar.Solid</item>
</style>
<style name="Widget.MyApp.ActionBar.Solid"
parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/TextAppearance.MyApp.Widget.ActionBar.Title</item>
</style>
<style name="TextAppearance.MyApp.Widget.ActionBar.Title"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textAllCaps">true</item>
</style>

Related

SnackBar using ActionBar Theme?

I having this weird behavior with the styling of ActionBar and Snackbar.
I have below theme for AppTheme
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorWhiteDark</item>
<item name="colorAccent">#color/colorGreen</item>
</style>
So, I am having white theme. And my SnackBar looks like this
But, whenever I add custom actionBarTheme, like
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorWhiteDark</item>
<item name="colorAccent">#color/colorGreen</item>
<item name="actionBarTheme">#style/ActionbarTheme</item>
</style>
<style name="ActionbarTheme">
<item name="android:textColor">#color/colorBlack</item>
<item name="android:background">#color/colorWhite</item>
</style>
My SnackBar looks like this
Why it is causing this behavior and how to fix it?
Since you are applying following style in your parent
<style name="ActionbarTheme">
<item name="android:textColor">#color/colorBlack</item>
<item name="android:background">#color/colorWhite</item>
</style>
Your text color is black and your background is white.
EDIT:
To fix, you need to set textcolor as white and background black:
<style name="ActionbarTheme">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:background">#color/colorBlack</item>
</style>
change item name background to colorPrimary
<style name="ActionbarTheme">
<item name="android:textColor">#color/colorBlack</item>
<item name="colorPrimary">#color/colorWhite</item>
</style>

How to change the theme of contextual action bar

I have use toolbar in my app with style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/holo_blue</
<item name="actionModeStyle">#style/Search.ActionMode</item>
<item name="windowActionModeOverlay">true</item>
</style>
Then I used a contextual action bar and able to change the background color.
<style name="Search.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/actionModeColor</item>
</style>
But I am unable to change the background color of popup menu.
Here is the image
And I wanted the background color of popup menu to be white. I also tried to change the theme by Widget.AppCompat.Light.ActionBar in Search.ActionMode but it does nothing.
There is an easy way to change the colors in Actionbar Use ActionBar Generator:
http://jgilfelt.github.io/android-actionbarstylegenerator/
and copy paste all file in your res folder and change your theme in Android.manifest file.
I have faced the same problem as yours. What I did is
I changed from
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
to
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
solve the problem. (Not exactly sure the reason behind)
(https://stackoverflow.com/a/50114013/72437)

Styling the android action bar?

I'm trying to style the action bar inside my app using the code below.
<resources>
<!-- the theme applied to the application or activity -->
<style name="myTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:textSize">24sp</item>
</style>
simply put the font should be bigger.. but nope.
Any ideas as to why?
Thanks.
Possibly your theme is not applied to activity. Set it in manifest:
<activity
android:name=".YourActivty"
android:theme="#style/myTheme" />
UPDATE 1
You should change action bar text size in such way (changing titleTextStyle):
<style name="Theme.YourTheme" parent="android:style/Theme">
<item name="android:actionBarStyle">#style/Theme.YourTheme.Styled.ActionBar</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar">
<item name="android:titleTextStyle">#style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">24sp</item>
</style>

can we set actionbar height manually in android theme.light

I am using "Theme.Light" theme for my android project and while setting up a navigation drawer how can i set actionbar size(height).
I used the below code and i got an error..
<style name="Theme.Light.ActionBar" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="actionBarSize">36dip</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
can you please reply to my problem as soon as possible and thank you.
Use height attribute,for actionBarHeight
<item name="android:height">#dimen/bar_height</item>
you have to create style like this:
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
you have to try below code :
<resources>
<style name="Theme.FixedSize" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="actionBarSize">48dip</item>
<item name="android:actionBarSize">48dip</item>
</style>
</resources>
If you are using AppCompat, you can set the "actionBarSize" attribute in your theme (which must inherit from Theme.AppCompat.x). You can also use a Toolbar in your layout and set its layout_height to the desired value.

Theme.AppCompat.Light.DarkActionBar giving black actionbar title text

I have been trying to set white text on the actionbar. I went through many questions and I am using theme Theme.AppCompat.Light.DarkActionBar and currently using this xml:
<style name="TrasnparentActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="TransparentActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_transparent_background</item>
<item name="android:titleTextStyle">#style/TransparentTransparentActionBarText</item>
</style>
<style name="TransparentTransparentActionBarText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
I have tried different combinations for eg: setting android:titleTextStyle, actionmenutextcolor, or using the actionBar Style Generator. None are working for me.
The above code is from values-v11 but a similar code is in values folder too.
#drawable/actionbar_transparent_background is just a shape with <solid android:color="#00000000"/>
In order to have white text (so dark action bar with light theme) you have to inherit your actionbar style from the correct object: Widget.AppCompat.Light.ActionBar.Solid.Inverse and not Widget.AppCompat.ActionBar.Solid
Here is the style.xml file :
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- action bar -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>

Categories

Resources