0

I have setup the following AppBarLayout + TabLayout for the main activity of my Android app.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.LinearLayout
    android:id="@+id/main_layout"
    android:orientation="vertical"
    ...>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        ...>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            ... />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="fill">

        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    ...

Basically it looks like this:

enter image description here

The question is: How can I pragmatically change the color of the home icon (the hamburger icon in the picture)?

Setting the color within my the XML syltes is no problem:

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorSecondary">#ff00ff00</item>
    ...
</style>

But how can I change this pragmatically at runtime? There seems to be no setter for textColorSecondary...

Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • 1
    Are you setting that icon yourself? Or is it coming from an `ActionBarDrawerToggle`? If the former, you could first load the image as a `Drawable`, set that on the `Toolbar`, then control the color with `Drawable`'s `setColorFilter()` or `setTint()` methods. If the latter, there's the `getDrawerArrowDrawable()` method, and you can `setColor()` directly on that. – Mike M. Feb 06 '18 at 01:02
  • Thanks, using `getDrawerArrowDrawable()` solved the problem! – Andrei Herford Feb 06 '18 at 09:54

1 Answers1

0

As far as i know, I do not believe you can set the style programatically. What you can do, however, is changing the style ( while keeping the same values) but only changing textColorSecondary value

Ahmed Abidi
  • 1,047
  • 12
  • 24