4

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>
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Ravi
  • 117
  • 1
  • 8
  • 2
    http://stackoverflow.com/questions/26439572/how-to-style-the-drawerarrowtoggle-from-android-appcompat-v7-21-library – Raghunandan Feb 14 '17 at 06:08

2 Answers2

7

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);
Hemanth S
  • 669
  • 6
  • 16
2

You can use a custom image and specify the same in styles as below

<item name="homeAsUpIndicator">@drawable/ic_back</item>
<item name="android:homeAsUpIndicator">@drawable/ic_back</item>
Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24