Change action bar Title font & color - java

I wanna change my action bar title font & color. so now im doing like this code. also i'm using typekit library too. i dont know why not change now
plz have some advice for me
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorCyanAzure</item>
<item name="colorPrimaryDark">#color/colorWhite</item>
<item name="colorAccent">#color/colorMelon</item>
<item name="android:actionBarStyle">#style/AppTheme.MyActionBar</item>
</style>
<style name="AppTheme.MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.MyActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.MyActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textStyle">normal</item>
</style>

Change you Theme.AppCompat.Light to Theme.AppCompat.Light.DarkActionBar and tried code as below
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="AppTheme.MyActionBar"parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTheme.MyActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textStyle">normal</item>
</style>

You could use a toolbar. When you have a reference to the toolbar and you want to style the title, you could do something like this
TextView textView = (TextView)toolbar.getChildAt(0);
//set the font and font color.
If you have more children in the toolbar, you may want to loop through and find the child you want to style

Related

I want to change title bar text color in material Components theme. Any help will be greatly appreciated

I tried set title color but it is deprecated. I tried to change color by using
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
as mentioned here: ActionBar text color but the whole Titlebar color changes to white while doing it.
All I want to do is set my Black Title bar text color to white.
I also tried this solution here: Change color title bar but I am using the MaterialComponents theme and using AppCompactThemes makes my app crash.
Assuming that you are not using a Toolbar the textcolor used in the ActionBar is based on the attribute android:textColorPrimary.
You can override it adding in your app theme the actionBarTheme attribute:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionBarTheme">#style/ThemeOverlay.Actionbar</item>
</style>
with:
<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.ActionBar.Surface" >
<item name="android:textColorPrimary">#color/....</item>
</style>
As alternative you can
just add this to you base theme
<item name="titleTextColor">#android:color/holo_red_dark</item> //whatever color
Eg:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="titleTextColor">#android:color/holo_green_dark</item>
</style>

How to Change swipe Tab Title color in java Android

By Default, the View Pager(Swipe Tabs) Tab title color is White but i want to change into orange. Can any one help me please or share if you have any tutorial.
Thanks...
Use this style in your styles.xml and assign the style to your tab layout.
<style name="MyMaterialTheme.TabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabIndicatorHeight">3dp</item>
<item name="tabTextAppearance">#style/MyMaterialTheme.TabLayout.TextAppearance</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
</style>
<style name="MyMaterialTheme.TabLayout.TextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#color/tab_text_inactive</item>
<item name="textAllCaps">true</item>
</style>
Check implementation from here.

How to hide the action-bar in style xml themes while loading

I have a custom theme that I displayed for my application. However, in my main activity class I set a custom font for the action bar font.
// Make sure you find out why it appears after a whole 1 second after the app appears
SpannableString s = new SpannableString("GetDisciplined");
s.setSpan(new TypefaceSpan(this, "roboto-light.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getActionBar();
actionBar.setTitle(s);
// set the action bar in this activity as the home
actionBar.setHomeButtonEnabled(true);
Upon launching the app, I want to immediately show the custom font.
I did some research and most solutions didn't work, but I am trying to now use launch a "splash screen" application theme without an action bar and then set the custom_theme with an action in my main activity class.
Kind of like this.
https://stackoverflow.com/a/12724687/3120659
But I am unsure how to do that modify my current style theme to do that.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Light_appalled" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_light_appalled</item>
<item name="popupMenuStyle">#style/PopupMenu.Light_appalled</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Light_appalled</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Light_appalled</item>
<item name="actionDropDownStyle">#style/DropDownNav.Light_appalled</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Light_appalled</item>
<item name="actionModeBackground">#drawable/cab_background_top_light_appalled</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_light_appalled</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Light_appalled</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.Light_appalled.Widget</item>
</style>
<style name="ActionBar.Solid.Light_appalled" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_light_appalled</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_light_appalled</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_light_appalled</item>
<item name="progressBarStyle">#style/ProgressBar.Light_appalled</item>
</style>
<style name="ActionBar.Transparent.Light_appalled" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/ab_transparent_light_appalled</item>
<item name="progressBarStyle">#style/ProgressBar.Light_appalled</item>
</style>
<style name="PopupMenu.Light_appalled" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_light_appalled</item>
</style>
<style name="DropDownListView.Light_appalled" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_light_appalled</item>
</style>
<style name="ActionBarTabStyle.Light_appalled" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_light_appalled</item>
</style>
<style name="DropDownNav.Light_appalled" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_light_appalled</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_light_appalled</item>
<item name="android:dropDownSelector">#drawable/selectable_background_light_appalled</item>
</style>
<style name="ProgressBar.Light_appalled" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_light_appalled</item>
</style>
<style name="ActionButton.CloseMode.Light_appalled" parent="#style/Widget.AppCompat.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_light_appalled</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Light_appalled.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Light_appalled</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Light_appalled</item>
</style>
</resources>
Unfortunately
<item name="android:windowNoTitle">true</item>
did not work, so I am trying to figure out how to do it.

Why can't I change my actionbar text color?

I used this generator to create a custom theme for my app:
http://jgilfelt.github.io/android-actionbarstylegenerator/
But there is one thing that i want to change, that this generator does not support:
The textcolor of the actionbar.
I tried doing this manually with this code:
<resources>
<style name="Theme.Bessel" parent="#android:style/Theme.Holo.Light">
<item name="android:titleTextStyle">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#F8F8FF</item>
</style>
</resources>
But the textcolor of my actionbar remains unchanged. Any tips?
Update:
<resources>
<style name="Theme.Bessel" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/Your.ActionBar</item>
</style>
<style name="Your.ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_background_textured_bessel</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_bessel</item>
<item name="android:backgroundSplit">#drawable/ab_background_textured_bessel</item>
<item name="android:progressBarStyle">#style/ProgressBar.Bessel</item>
<item name="android:titleTextStyle">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#F8F8FF</item>
</style>
</resources>
You need to be applying android:titleTextStyle to a style that is inherent of Widget.ActionBar. So, it looks like in your case that would be Widget.Holo.Light.ActionBar.
<style name="Your.ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTextAppearance</item>
</style>
Then apply your ActionBar style in your root theme using android:actionBarStyle.
<style name="Theme.Bessel" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/Your.ActionBar</item>
</style>
To change the tab text color, you need a theme that inherits Widget.ActionBar.TabText, in your case that looks like it'll be Widget.Holo.Light.ActionBar.TabText. Then to apply the style use android:actionBarTabTextStyle in your root theme.
<style name="Theme.Bessel" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarTabTextStyle">#style/Your.Widget.ActionBar.TabText</item>
</style>
<style name="Your.Widget.ActionBar.TabText" parent="#android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">#F8F8FF</item>
</style>

Change the action bar settings icon color

How can one change the color of the overflow icon in the action bar?
(The most right icon)
You can use something like this
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/my_action_bTutton_overflow</item>
</style>
in your AndroidManifest.xml
<application
android:theme="#style/MyTheme" >
If you want to change actionBar color
#style/MyActionBar
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/app_theme_color</item>
<!-- Support library compatibility -->
<item name="background">#color/app_theme_color</item>
<item name="android:alwaysDrawnWithCache">true</item>
<item name="android:displayOptions">showTitle|showHome|homeAsUp</item>
<item name="android:icon">#android:color/transparent</item>
</style>
Then in your AndroidManifest.xml you need to refer this one inside your application tag.
android:theme="#style/CustomActionBarTheme"
If you just want to change the color you can simply tint it:
<style name="DotsDarkTheme" parent="#style/Widget.AppCompat.ActionButton.Overflow" >
<item name="android:tint">#color/yourColor</item>
</style>
and then use it in your style:
<item name="actionOverflowButtonStyle">#style/DotsDarkTheme</item>
if you are using action bar use :
toolbar.getOverflowIcon().setColorFilter(Color.WHITE , PorterDuff.Mode.SRC_ATOP);
It's also worth adding that if you simply want to change the overflow button to a light or dark colour to go with your action bar colour this can be done without specifying a custom icon.
For a dark button colour set your theme as:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
</style>
For a light button colour add DarkActionBar:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
</style>
If, like me, you want a light button colour but you want the overflow menu to be light you can do the following:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
<item name="android:actionBarWidgetTheme">#style/MyTheme.ActionBarWidget</item>
</style>
<!-- This helps the PopupMenu stick with Light theme while the ActionBar is in Dark theme -->
<style name="MyTheme.ActionBarWidget"
parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#android:style/Widget.Holo.Light.PopupMenu</item>
<item name="android:dropDownListViewStyle">#android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>
You can use your custom style inside for menu item, like this
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
Define the style like this:
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/primary_text_dark</item>
</style>
Also see Change the background color of the options menu and
Android: customize application's menu (e.g background color)
Create below style in styles.xml with parent as ActionButton Overflow widget
and then use that theme in the style that you are using for that activity where toolbar is shown.
Step-1) Creating style for the actionButtonOverflow
<style name="DotsDarkTheme" parent="#style/Widget.AppCompat.ActionButton.Overflow" >
<item name="android:tint">your color</item>
</style>
Step-2) Using this style in the activity that is using actionBar
<style name="CustomMainActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionOverflowButtonStyle">#style/DotsDarkTheme</item>
</style>

Categories

Resources