Get Toolbar's navigation icon view referrence

I would like to highlight drawer icon in my Toolbar (working on a tutorial). For that, I need its position. How do I get a reference to drawer’s navigation icon (hamburger) view?

  • Can one use cardview for listview item and how
  • Android - How to circular zoom/magnify part of image?
  • Does Android plan to support Java7?
  • Android coding best practices/design patterns
  • (The system cannot find the file specified)
  • Android: Can you nest Fragments?
  • Related posts:

    Toggling A2DP Device (Android)
    Events of TextWatcher are being called twice
    Emoji (Emoticons) on Blackberry and Android App. How to support?
    Android ActionBar's custom view not filling parent
    Emulator for Android 4.4 KitKat is not starting
    How to Implement Swipe In Android Game Without View
  • Unable to instantiate receiver in BroadcastReceiver SMS
  • playback video full screen
  • Modifying camera output using SurfaceTexture and OpenGL
  • Create a cursor from hardcoded array instead of DB
  • REST server framework for Android
  • java.lang.IllegalArgumentException: Illegal character in scheme at index 0:
  • 3 Solutions collect form web for “Get Toolbar's navigation icon view referrence”

    You can make use of content description of the view and then use findViewWithText() method to get view reference

     public static View getToolbarNavigationIcon(Toolbar toolbar){
            //check if contentDescription previously was set
            boolean hadContentDescription = TextUtils.isEmpty(toolbar.getNavigationContentDescription());
            String contentDescription = !hadContentDescription ? toolbar.getNavigationContentDescription() : "navigationIcon";
            ArrayList<View> potentialViews = new ArrayList<View>();
            //find the view based on it's content description, set programatically or with android:contentDescription
            toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            //Nav icon is always instantiated at this point because calling setNavigationContentDescription ensures its existence 
            View navIcon = null;
            if(potentialViews.size() > 0){
                navIcon = potentialViews.get(0); //navigation icon is ImageButton
             //Clear content description if not previously present
            return navIcon;


    After looking into Toolbar’s child views in debug mode, I saw that drawer icon can be found there, as an ImageButton. (Thanks Elltz)

    I use a Toolbar with custom xml layout with 2 children (LinearLayout and ImageView), so my Toolbar had 4 children in the end, with these positions:

    [0] LinearLayout(from custom xml)
    [1] ImageView(from custom xml)
    [2] ImageButton(drawer icon)
    [3] ActionMenuView(menu icon)

    Knowing this, I can now use:

    View drawerIcon = toolbar.getChildAt(2);

    to get a reference to drawer menu icon. In my case, the position is 2. This position should be equal to the number of child view’s in your custom toolbar layout.

    If someone finds better solution please let me know.

    If you just want to get the Drawable representing the toolbar navigation icon, you can do this:

    Drawable d = mToolbar.getNavigationIcon();

    You can get a reference to the ImageButton used for the toolbar’s navigation icon by having a method as this:

    public ImageButton getToolbarNavigationButton() {
        int size = mToolbar.getChildCount();
        for (int i = 0; i < size; i++) {
            View child = mToolbar.getChildAt(i);
            if (child instanceof ImageButton) {
                ImageButton btn = (ImageButton) child;
                if (btn.getDrawable() == mToolbar.getNavigationIcon()) {
                    return btn;
        return null;
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.