Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of homeAsUpIndicator in android?

Tags:

android

I am developing an app in which I have one activity known as "AboutPreference" which extends PreferenceActivity and I had added a toolbar in postCreate() method. Problem is that I want to change "homeAsUpIndicator" color from black to white. How do i do that

code:-

 protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
        Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.about_toolbar, root, false);
        root.addView(bar, 0); // insert at top
        bar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

toolbar

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:theme="@style/ToolTheme"
app:title="About Us"
tools:ignore="PrivateResource"/>

and here is style

 <style name="ToolTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorSecondary">@color/white</item>
    <item name="android:textColorPrimaryInverse">@color/white</item>
    <item name="android:textSize">20sp</item>
    <item name="android:homeAsUpIndicator">@color/White</item>
    <item name="colorPrimary">#F5560A</item>
    <item name="colorPrimaryDark">@color/accent</item>
    <item name="android:navigationBarColor">@color/accent</item>
    <item name="colorAccent">@color/accent</item>
</style>
like image 928
Ravi Avatar asked Jan 05 '23 13:01

Ravi


1 Answers

By accessing navigation icon from toolbar we can change color

toolbar.getNavigationIcon().setColorFilter(color, PorterDuff.Mode.SRC_IN);

if its not working try this

toolbar.getNavigationIcon().mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
like image 73
Hemanth S Avatar answered Jan 18 '23 20:01

Hemanth S