How to set Toolbar text and hamburger icon to be white? - android

Toolbar text and hamburger icon is in black color and I want in white color.
I have tried this, this and this solution but nothing worked.
Source code link: https://github.com/vaibhavsingh97/Solucion/tree/master/Android%20Basic%20Nanodegree/Project%206/TourGuide
Styles.xml
<!-- 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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
</resources>
app_bar_main.xml
<android.support.design.widget.AppBarLayout
style="#style/AppTheme.AppBarOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_home" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#drawable/ic_play"/>
</android.support.design.widget.CoordinatorLayout>
Android Studio: 3.0 Canary 9
SDK used for build: 26

Inside Activity, you can use
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
If you love to choose xml for both title color & back arrow white just add this style in style.xml .
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
And toolbar look like :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
app:theme="#style/ToolBarStyle"
android:layout_height="?attr/actionBarSize"
/>
UPDATE
try this
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/black</item>
</style>
So check <item name="color">#android:color/black</item> line. Just change your desired color here.

try darkActionBar theme as toolbar style in XML file

Related

Change color of of menu drawer hamburger icon in Android

I would like to change the icon color from of the hamburger icon. I tried a lots things and nothing worked. Here my XML:
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:titleTextColor="#color/colorPrimaryDark"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
android:elevation="4dp"/>
In styles.xml I have
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Looks like you are using AppCompat. Please create this or similar style:
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">#D81B60</item>
</style>
Then use it in your theme:
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>

Android Toolbar menu text color

I'm trying to change my Toolbar's menu item text color here, but it doesn't work. Here's my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarStyle">#style/AppTheme.ToolbarStyle</item>
<item name="buttonStyle">#style/AppTheme.ButtonStyle</item>
<item name="colorControlHighlight">#color/colorPrimary</item>
</style>
<style name="AppTheme.ToolbarStyle" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/colorPrimary</item>
<item name="titleTextColor">#android:color/white</item>
<item name="titleTextAppearance">#style/TextAppearance.AppCompat.Widget.ActionBar.Title
</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
layout xml:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="#string/app_name"
app:titleMarginStart="#dimen/margin_l"
/>
I have tried to set the Toolbar theme directly in xml, but the menu item is still back. Is there a solution to this?
Add these lines in your AppTheme style
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
Having a material toolbar you can play with styling modifying text title and menu texts as follows:
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#android:color/white"
android:elevation="6dp"
android:theme="#style/App.ToolbarStyle"
app:titleTextAppearance="#style/App.ToolbarTitleTex"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/create_item_menu"
app:titleTextColor="#android:color/black" />
Where this style lets you change the color of the icon of the left:
<style name="App.ToolbarStyle" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorOnPrimary">#color/colorPrimary</item>
</style>
Also you can change the title text appearance with another style:
<style name="App.ToolbarTitleTex" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">18sp</item>
<item name="fontFamily">#font/roboto_bold</item>
</style>
And finally to change the menu item style you need to add this item property to the main style/theme of the app (the one you set in the AndroidManifest file:
<item name="actionMenuTextAppearance">#style/App.ToolbarMenuItem</item>
With:
<style name="App.ToolbarMenuItem" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">14sp</item>
<item name="fontFamily">#font/roboto_bold</item>
<item name="textAllCaps">true</item>
<item name="android:textStyle">bold</item>
</style>
The final result would be something like this:
You need to declare a Theme like this
<style name="Theme.PopupOverlay.Menu" parent="ThemeOverlay.AppCompat.Light" >
<item name="android:textColor">#android:color/white</item>
</style>
And then, in your Toolbar in layout view you must specify to use that theme
<androidx.appcompat.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/Theme.PopupOverlay.Menu" />
Modern way under Material3 theming.
<style name="AppTheme" parent="Theme.Material3.Dark">
<item name="toolbarStyle">#style/ToolBarStyle</item>
...
</style>
<style name="ToolBarStyle" parent="#style/Widget.Material3.Toolbar">
<item name="titleTextColor">#android:color/holo_green_light</item>
<item name="navigationIconTint">#android:color/holo_blue_light</item>
<item name="materialThemeOverlay">#style/ToolbarThemeOverlay</item>
</style>
<style name="ToolbarThemeOverlay" parent="">
<item name="actionMenuTextColor">#android:color/holo_red_light</item>
</style>
materialThemeOverlay - is the key to apply the colors to action menu items
In your theme file you have to put this :
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionMenuTextColor">#color/text_color</item>
...
</style>
and apply above theme to Toolbar view as like this android:theme="#style/AppTheme.ActionBar"
detailed example:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_gravity="top"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/AppTheme.ActionBar"/>

Android change Actionbar background color using AppCompat

I'm trying to change the background color of my ActionBar as well as the title color. I must say I am using the support library.
My styles are as follows.
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/red_300</item>
<item name="android:background">#color/red_300</item>
<item name="colorPrimary">#color/red_300</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.Title</item>
</style>
<style name="AppTheme.ActionBar.Title" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/red_700</item>
<item name="android:textColorPrimary">#00FF00</item>
</style>
And in styles-v21
<style name="AppTheme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/red_300</item>
<item name="android:background">#color/red_300</item>
<item name="colorPrimary">#color/red_300</item>
<item name="android:colorPrimary">#FF0000</item>
<item name="android:colorAccent">#FF0000</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.Title</item>
</style>
<style name="AppTheme.ActionBar.Title" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:colorPrimary">#FFFF00</item>
<item name="android:colorAccent">#FFFF00</item>
<item name="android:textColor">#color/red_700</item>
<item name="android:textColorPrimary">#00FF00</item>
</style>
As you guys might see by the amount of attemps to change it, I am already losing my mind. Any clues as to how I can change the ActionBar background and it's title color?
I must note that I am trying this on Android 6.
In the ToolBar creation (xml), setting the app:theme fixed it. Specifying a theme there with it's colorPrimary changed the background of the ActionBar without affecting the base theme.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
and the theme:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
</style>

Android toolbar shadow

So I created a toolbar and tabview, but I can't remove the shadow below the toolbar as you can see here:
This is my toolbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
android:id="#+id/toolBar"
android:elevation="0dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
</android.support.v7.widget.Toolbar>
What am I missing? I tried to remove shadow with all methods I could find on Internet, but none of them helped.
If you need me to upload any more core just say!
Thanks!
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="elevation">0dp</item>
-->
<item name="android:windowContentOverlay">#null</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="elevation">0dp</item>
-->
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="elevation">0dp</item>
/>
</style>
</resources>
styles v21
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:elevation">0dp</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
Activity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vjezbe);
toolbar = (Toolbar) findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setElevation(0);
use app:elevation="0dp" instead of android:elevation
You have to do it programatically...
getSupportActionBar().setElevation(0);
and change ur style to
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#5C2D91</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
and set the actionbar style as
<item name="android:actionBarStyle">#style/MyActionBar</item>
in
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Android statusbar and actionbar resolve to grey

I recently split my values into two:
values/style.xml
values-v21/style.xml
my v21/style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Foodie" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
</style>
</resources>
my style.xml
<resources>
<style name="Theme.Foodie" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="windowActionModeOverlay">true</item>-->
<item name="colorPrimary">#color/theme_primary</item>
<item name="colorPrimaryDark">#color/theme_primary_dark</item>
<item name="colorAccent">#color/theme_accent</item>
</style>
</resources>
And my toolbar:
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_actionbar"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_height="?actionBarSize"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
Somehow, we toolbar background's resolve to grey! Same for the statusbar when I compile:
And I'm not sure if that's linked, but I recently cleaned my project before building it.
Do you know what's happening?
Use Toolbar code like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
//..........
</android.support.v7.widget.Toolbar>
and in style.xml will like this:
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Categories

Resources