3

I'm using getSupportedActionBar().setTitle("This Phone");

I have managed to change the title color to white by using Toolbar.setTitleTextColor(0xFFFFFFFF);

How do I change the back arrow key color to white too?

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44

6 Answers6

4

You can try this in your activity :- (After setSupportActionBar(toolbar) )

  Drawable backArrow = context.getResources().getDrawable(R.drawable.your_back_button);
  backArrow.setColorFilter(getResources().getColor(R.color.yourcolor), PorterDuff.Mode.SRC_ATOP);
  getSupportActionBar().setHomeAsUpIndicator(backArrow);
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
2

Please have look below kotlin function which is working for me.

private fun setToolbarProperties() {
    setSupportActionBar(toolbar)
    supportActionBar?.setDisplayHomeAsUpEnabled(true)
    supportActionBar?.title = "" //If you don't want to set title
    val upArrow = resources.getDrawable(R.drawable.ic_action_back,theme);
    supportActionBar?.setHomeAsUpIndicator(upArrow);
}

Below is a toolbar xml code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="@android:color/transparent"
    android:orientation="vertical"
    >

</androidx.appcompat.widget.Toolbar>
Hitesh Dhamshaniya
  • 2,088
  • 2
  • 16
  • 23
1

Joy Dey.
Try to change your app theme to "Theme.AppCompat.Light.NoActionBar" in styles.xml.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style> 
Porush Manjhi
  • 135
  • 12
1

Try changing the icon itself in styles.xml like this

    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

            <item name="android:homeAsUpIndicator">@drawable/ic_new_icon</item>
    </style>
Dawit Abraham
  • 1,616
  • 15
  • 19
0

Try with below code :

Take image from drawable and then set color

final Drawable backArrow = getResources().getDrawable(R.drawable.back_img);
backArrow .setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow );

If you want to change color of ToolBar title & back button image to white by style

Reference : https://stackoverflow.com/a/33339983/8448886

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
0

Add below code in your style.xml

<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.ActionBar">
  <!-- Customize color of navigation drawer icon and back arrow --> 
  <item name="colorControlNormal">@color/toolbar_color_control_normal</item>
</style>

And add this attribute app:theme="@style/ToolbarStyle" in your toolbar

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ToolbarStyle" >
</android.support.v7.widget.Toolbar>
MashukKhan
  • 1,946
  • 1
  • 27
  • 46