Sanket Kachhela
Sanket Kachhela

Reputation: 10876

how to change icon of navigation drawer DrawerArrowToggle?

hello i am using AppCompat v7 for Navigation drawer. i required to change hamburger menu icon with no animation.

enter image description here

i gone through style of DrawerArrowToggle and found this

<style name="Base.Widget.AppCompat.DrawerArrowToggle" parent="">
        <item name="color">?android:attr/textColorSecondary</item>
        <item name="thickness">2dp</item>
        <item name="barSize">18dp</item>
        <item name="gapBetweenBars">3dp</item>
        <item name="topBottomBarArrowSize">11.31dp</item>
        <item name="middleBarArrowSize">16dp</item>
        <item name="drawableSize">24dp</item>
        <item name="spinBars">true</item>
    </style>

and there is no drawable attribute to set custom icon. so is there way to change icon?

i know we can disable drawerToggle and set custom image in toolbar and maintain open and close state.

Upvotes: 0

Views: 1545

Answers (1)

Christopher
Christopher

Reputation: 10279

I think currently this is not possible if you use v7 ActionBarDrawerToggle. This class has only a package-local constructor which allows you to change the burger-menu / slider.

Source: https://android.googlesource.com/platform/frameworks/support/+/master/v7/appcompat/src/android/support/v7/app/ActionBarDrawerToggle.java

/**
 * In the future, we can make this constructor public if we want to let developers customize the animation.
 */
<T extends Drawable & DrawerToggle> ActionBarDrawerToggle(Activity activity, Toolbar toolbar, DrawerLayout drawerLayout, T slider, @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) {
    // some code
    if (slider == null) {
        mSlider = new DrawerArrowDrawableToggle(activity,
        mActivityImpl.getActionBarThemedContext());
    } else {
       mSlider = slider;
   }

}

As a (bad) workaround I would suggest you to continue using the old v4 ActionBarDrawerToggle, which allows the customization of the burger icons.

Please notice that you can customize the default animation-slider as described in this SO-comment: https://stackoverflow.com/a/26447144/2960788

Furthermore you could tint the slider by setting

<item name="colorControlNormal">#ccffffff</item>

in your toolbar's theme.

Upvotes: 1

Related Questions