How to change only the back arrow in toolbar?

0

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?

android
android-layout
android-relativelayout
asked on Stack Overflow Mar 7, 2018 by (unknown user) • edited Mar 7, 2018 by Abhishek kumar

6 Answers

1

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);
answered on Stack Overflow Mar 7, 2018 by Santanu Sur
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> 
answered on Stack Overflow Mar 7, 2018 by Porush Manjhi
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>
answered on Stack Overflow Oct 25, 2018 by Dawit Abraham • edited Dec 6, 2018 by Dawit Abraham
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

answered on Stack Overflow Mar 7, 2018 by Abhishek kumar • edited Mar 7, 2018 by Abhishek kumar
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>
answered on Stack Overflow Mar 7, 2018 by MashukKhan
0

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>
answered on Stack Overflow Feb 12, 2020 by Hitesh Dhamshaniya

User contributions licensed under CC BY-SA 3.0