Updated 26 October 2021
In this article, we will look how we can change navigation menu icon in Android.
The Navigation icon(displayed as ☰) is actually a button in the action bar and is known as the hotdog or hamburger button.It is often placed on the top left or top right of a user interface and is so called for its resemblance to a hotdog or hamburger.
If your activity/fragment has no action bar and is using a toolbar, then changing it programmatically is very very easy and is just one line of code. You just need to add this line after you have set drawer toggle
1 2 |
mDrawerToggle = new ActionBarDrawerToggle(this.getActivity(), mBinding.drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close); toolbar.setNavigationIcon(R.drawable.your_drawable_name); |
But if you are not using any toolbar and you wish to change this icon then you need to follow a procedure and you can easily successfully replace the navigation icon.
Let’s first look at how you can change the color of the default navigation icon. For this, all you need to do is add a custom style to your styles.xml file.
1 2 3 4 |
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle"> <item name="spinBars">true</item> <item name="color">@color/your_color_name</item> </style> |
And use this style in your app theme like this :
1 |
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item> |
But if you wish to change the whole icon, then you need to add this line:
1 |
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_your_drawer_icon); //set your own |
Hope this article helps you.
Keep coding, Keep sharing.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
7 comments
as explained in the blog as well.
If you are getting an error due to this then you can simply replace the “mBinding.drawerLayout” with findViewByid function.
Hope this helps you.
You can find more solutions on our website technical blogs. ( Reference –> https://mobikul.com/blog/ )
We focus on writing technical blogs so that we can uplift the community.