Search code examples
androidandroid-actionbarandroid-themeandroid-stylesandroid-architecture-navigation

How to change the up button colour in Navigation Architecture Component


Here is my styles code

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/lightGrey</item>
    <item name="colorPrimaryDark">@color/black</item>
    <item name="colorAccent">@color/grey</item>
    <item name="colorControlNormal">@color/lightGrey</item>
</style>

<style name="TextAppearance.AppCompat.Widget.ActionBar.Title"
    parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/mediumBlack</item>
</style>

and here is the navigation UI code

val myNavController = this.findNavController(R.id.myNavHostFragment)
NavigationUI.setupActionBarWithNavController(this, myNavController)

Text changing colour works fine at style name "TextAppearance.AppCompat.Widget.ActionBar.Title" but I want to change the colour of the upButton. Its showing white by default, I want to change it to black.


Solution

  • In your app theme add the actionBarTheme attribute:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">   
        .....
        <item name="actionBarTheme">@style/MyActionBarTheme</item>
    </style>
    

    with:

    <style name="MyActionBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
        <item name="colorControlNormal">@color/....</item>
    </style>