Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] How to change the color of “Home” icon at the leftmost by using XML style in Android 10

Posted on November 11, 2022 By

Solution 1 :

With the help of @GabrieleMariotti, here is the answer for setting both “Home” and “Overflow” icons.

Firstly, remove android:theme attribute from AppBarLayout and Toolbar from layout xml:

<com.google.android.material.appbar.AppBarLayout
    android_layout_width="match_parent"
    android_layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
        android_id="@+id/toolbar"
        android_layout_width="match_parent"
        android_layout_height="?attr/actionBarSize"/>

</com.google.android.material.appbar.AppBarLayout>

Secondly, set the following items in the styles xml:

<style name="ActionButtonOverflow" parent="@style/Widget.AppCompat.ActionButton.Overflow" >
    <item name="android:tint">@color/yellow</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/red</item>
    <item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
</style>

Thanks.

Problem :

The ActionBar has two icons, one is the “Overflow” icon at the rightmost, the other is the “Home” icon (Three horizontal lines icon) at the leftmost.

The color of the ActionBar “Overflow” (Rightmost) icon can be changed by the following style:

<style name="ActionBarOverflowStyle" parent="@style/Widget.AppCompat.ActionButton.Overflow" >
    <item name="android:tint">@color/red</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionOverflowButtonStyle">@style/ActionBarOverflowStyle</item>
</style>

But how to change the color of “Home” icon at the leftmost by using XML style?

Also when navigating to the next fragment, the “Back” icon will appear in the ActionBar, how to change the color of “Back” icon at the leftmost by using XML style?

Here is the layout xml:

<com.google.android.material.appbar.AppBarLayout
    android_layout_width="match_parent"
    android_layout_height="wrap_content"
    android_theme="@style/AppTheme.PopupOverlay">

    <androidx.appcompat.widget.Toolbar
        android_id="@+id/toolbar"
        android_layout_width="match_parent"
        android_layout_height="?attr/actionBarSize"
        app_popupTheme="@style/AppTheme.AppBarOverlay" />

</com.google.android.material.appbar.AppBarLayout>

Here is the style xml:

<style name="MyThemeOverlay_Toolbar" parent="@style/ThemeOverlay.MaterialComponents.ActionBar">
    <item name="android:tint">@color/red</item>
    <item name="android:iconTint">@color/red</item>
    <item name="android:colorControlNormal">@color/red</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionOverflowButtonStyle">@style/ActionBarOverflowStyle</item>
    <item name="android:actionBarStyle">@style/MyThemeOverlay_Toolbar</item>
</style>

The color of “Menu” icon can’t be changed with this style configuration.

Thanks.

Comments

Comment posted by stackoverflow.com/questions/58074174/…

Check this

Comment posted by stackbiz

It’s not working in that link, I’m not use com.google.android.material.appbar.MaterialToolbar, I’m using androidx.appcompat.widget.Toolbar. I found a solution for java code: call Toolbar.setNavigationIcon can change the icon and the tint, but I don’t know how to set the color in XML style format. Thanks.

READ  [FIXED] android - Context not associated with any application instrumentation testing?
Powered by Inline Related Posts

Comment posted by stackbiz

But there is also a trouble for setting NavitationIcon in java code because it is required to setNavigationIcon in every Fragment. If there are 100 fragments, then must call setNavigationIcon 100 times. Please help to find the XML style solution

Comment posted by Gabriele Mariotti

You have to check if you are using a Material Components theme or AppCompat theme. With appcompat use the colorControlNormal as mentioned in the same link.

Comment posted by stackbiz

I have added more detail to the post, please help to check, thanks.

Android Tags:android, themes, xml

Post navigation

Previous Post: [FIXED] How to get Firebase auth token in Android login
Next Post: [FIXED] android – what should be the input and output forom of variables for float object detection model

Related Posts

[FIXED] Android Java file create java.io.FileNotFoundException (File name too long) Android
[FIXED] java – Retrieve location from Firebase and put marker on google map Android
[FIXED] java – Android licenses in Flutter Android
[FIXED] Android duplicate dependency problem in flutter Android
[FIXED] android – Creating SQLite Database table with Foreign Keys? Android
[FIXED] java – Firestore lecture operations count Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme