After several hours of try I give up... How to set bold font for action bar title? I have values/styles.xml below:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Background color -->
<item name="android:background">#f1a30b</item>
<!-- Menu text -->
<item name="android:textColor">#ffffff</item>
<item name="android:textStyle">bold|italic</item>
<!-- Ttle color -->
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:titleTextStyle">#style/AppTheme.MyActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.MyActionBar.TitleTextStyle" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:background">#81CFEB</item>
<item name="android:textColor">#000000</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Menu text color, style and background color OK. But how to change font for title (style and text size)? I need bold and 25dp.
I understand that in manifest I should only have line android:theme="#style/AppTheme" for application... nothing more. Should I import some class in activity?
You need to make override some properties for Theme which is explained Here.
Related
I am trying to change option menu background , but there is white space top and bottom
my toolbar style
app:popupTheme="#style/ThemeOverlay.MyTheme"
<style name="ThemeOverlay.MyTheme" parent="ThemeOverlay.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- To change the popup menu and app text color -->
<item name="android:textColor">#color/white</item>
<!-- To change the background of options menu-->
<item name="android:itemBackground">#color/black</item>
</style>
Example:
Are you searching for this?
Create style for menu in your app style and add that entry in theme of your app
don't forgot to add that theme in you menifest's Application tag
android:theme="#style/AppTheme"
There problem with the material theme
<style name="Theme.MyApplication" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#color/bluish_green</item>
</style>
<style name="ThemeOverlay.MyTheme" parent="Theme.MyApplication">
<!-- To change the popup menu and app text color -->
<item name="android:textColor">#color/white</item>
<!-- To change the background of options menu-->
<item name="android:itemBackground">#color/black</item>
<item name="android:popupBackground">#color/black</item>
<item name="android:drawablePadding">0dp</item>
<item name="android:dividerHeight">1dp</item>
</style>
I'm implementing a dark theme in my playground Android app, and am struggling to get the action bar text color to be white.
Below is my style and colors. The background of the action bar follows colorPrimary, which is great. However, both colors (light and dark) are pretty dark colors, and would like the action bar text color to always be white. Since I am using the DayNight.NoActionBar as the parent right now, it is black for light and white for dark. I have a few different instances of the action bar so I would prefer not to have to change each individual one, but rather just define it in the style. How do I go about doing this?
styles.xml
<style name="DarkThemeApp" parent="#style/Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorError">#color/colorError</item>
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>
night\colors.xml
<resources>
<color name="colorPrimary">#3d85c6</color>
<color name="colorPrimaryDark">#002e72</color>
<color name="colorAccent">#e66f00</color>
<color name="colorYellow">#FFE800</color>
<color name="colorError">#E53935</color>
</resources>
values\colors.xml
<resources>
<color name="colorPrimary">#00348e</color>
<color name="colorPrimaryDark">#002e72</color>
<color name="colorAccent">#e66f00</color>
<color name="colorYellow">#FFE800</color>
<color name="colorError">#E53935</color>
</resources>
Using a material theme you have different options to customize the text color used in the Toolbar
Use the android:theme to override default values only for your Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:theme="#style/MyThemeOverlay_Toolbar"
...>
and use:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<!-- color used by the toolbar title -->
<item name="android:textColorPrimary">#color/secondaryColor</item>
<!-- color used by navigation icon and overflow icon -->
<item name="colorOnPrimary">#color/secondaryColor</item>
</style>
Set a style in your Toolbar
<com.google.android.material.appbar.MaterialToolbar
style="#style/MyToolbar"
.../>
And then use the materialThemeOverlay to override the default values (it requires the material components library version 1.1.0):
<!-- Toolbar -->
<style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar">
<item name="materialThemeOverlay">#style/MyThemeOverlay_Toolbar</item>
</style>
<style name="MyThemeOverlay_Toolbar" parent="">
<item name="android:textColorPrimary">#color/secondaryColor</item>
<item name="colorOnPrimary">#color/secondaryColor</item>
</style>
First, add these three to your main style (you can name the styles whatever you want):
<item name="toolbarStyle">#style/ToolbarStyle</item>
<item name="actionOverflowButtonStyle">#style/ToolbarStyle.Overflow</item>
<item name="toolbarNavigationButtonStyle">#style/Toolbar.Button.Navigation.Tinted</item>
Then define those styles:
<style name="ToolbarStyle" parent="#style/Widget.AppCompat.Toolbar">
<!-- Makes the toolbar text whatever color you want for both light/dark-->
<item name="titleTextColor">#color/actionBarText</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
<style name="ToolbarStyle.Overflow" parent="Widget.AppCompat.ActionButton.Overflow">
<!-- For toolbar menu -->
<item name="android:tint">#color/actionBarText</item>
</style>
<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<!-- For the hamburger menu, back button, etc -->
<item name="tint">#color/actionBarText</item>
</style>
In new version of Android Studio, we have two files for theme colors. To change the dark theme, you should use this file:
Res > values > themes > themes.xml (night)
And for day version:
Res > values > themes > themes.xml
in your styles.xml use this code
<style name="DarkThemeApp" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleTextStyle</item>
</style>
<style name="MyActionBarTitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
I think the answer to this question might vary depending on what other components you use in your app. In my case the following was a working solution:
Define these three styles in styles.xml
<style name="ToolbarStyle" parent="#style/Widget.MaterialComponents.Toolbar">
<item name="titleTextColor">#android:color/white</item>
<item name="android:background">#color/primary</item>
</style>
<style name="ToolbarStyle.Overflow" parent="#style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">#android:color/white</item>
</style>
<style name="ToolbarStyle.DrawerIcon" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#android:color/white</item>
</style>
and then set them in your theme(s):
<style name="DarkThemeApp" parent="#style/Theme.MaterialComponents.DayNight.NoActionBar">
<!-- color for stuff in action bar -->
<item name="toolbarStyle">#style/ToolbarStyle</item>
<item name="actionOverflowButtonStyle">#style/ToolbarStyle.Overflow</item>
<item name="drawerArrowStyle">#style/ToolbarStyle.DrawerIcon</item>
<!-- rest of your attributes go here ... -->
</style>
There is this useful information and everything works well:
http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes
The image is also very helpful:
The problem is that I want to have white or very light gray in the top bar. When I set this as "android:textColorPrimary", however, the text is white in the top bar, but in all alerts for instance as well making it invisible/very difficult to read.
How can I set the text color of the bar to white and theme the alert messages and other text in the default text color (dark gray)?
The themeAndroid.xml in app/platform/android/res/values looks like this
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="materialTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#2e7d32</item>
<item name="colorPrimaryDark">#005005</item>
<item name="colorAccent">#80d8ff</item>
<item name="colorSwitchThumbNormal">#49a7cc</item>
<item name="android:colorButtonNormal">#49a7cc</item>
<item name="android:textColorPrimary">#DADADA</item>
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItem</item>
</style>
If you want to style the color of the actionbar font you need to extend your theme like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyThemeActionbar" parent="Theme.AppCompat">
<item name="colorPrimary">#FF0000</item>
<item name="colorPrimaryDark">#000000</item>
<item name="actionBarStyle">#style/CustomTheme.ActionBarStyle</item>
<item name="actionBarTheme">#style/Theme.ActionBarTheme</item>
<!-- tab -->
<item name="actionBarTabTextStyle">#style/TabStyle</item>
<item name="android:actionBarTabTextStyle">#style/TabStyle</item>
</style>
<style name="Theme.ActionBarTheme" parent="style/Widget.AppCompat.Light.ActionBar">
<!-- actionbar arrow -->
<item name="colorControlNormal">#ffffff</item>
</style>
<style name="CustomTheme.ActionBarStyle" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- actionbar -->
<item name="elevation">0dp</item>
<item name="android:actionMenuTextColor">#FFFFFF</item>
<item name="android:titleTextStyle">#style/CustomTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/CustomTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="CustomTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<!-- actionbar font -->
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="TabStyle" parent="style/Widget.AppCompat.Light.ActionBar.TabText">
<!-- tab font -->
<item name="android:textColor">#ffffff</item>
</style>
</resources>
Then you can set the font color and the primary color to a different value and leave other thinks to the default values
I'd like to change the background color of the option (overflow) menu in Android above 5.0. I have tried all the methods but it is still showing the default color set by the theme. I used the following code & XML configs.
There is an easy way to change the colors in Actionbar Use ActionBar Generator and copy paste all file in your res folder and change your theme in Android.manifest file.
Other way is to modify your styles.xml like this-
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- This is the styling for action bar -->
<item name="actionBarStyle">#style/MyActionBar</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">#color/skyBlue</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/red</item>
<item name="titleTextStyle">#style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">25sp</item>
</style>
and this is how it looks--MenuItem background color is skyblue and MenuItem text color is pink with textsize as 25sp:--
This answer is taken from here.
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>