How can you disable the default "UP" button in Toolbar beside the ic_launcher? I want to leave only the ic_launcher at the left.
-
check this http://stackoverflow.com/questions/26525229/toolbar-navigation-icon-never-set if it helps – Raghunandan Jan 22 '15 at 03:02
7 Answers
If you're using Toolbar
(android.support.v7.widget.Toolbar
or native) in order to disable navigation button just call:
toolbar.setNavigationIcon(null);
From documentation:
/**
* Set the icon to use for the toolbar's navigation button.
* ...
* @param icon Drawable to set, may be null to clear the icon
*/
public void setNavigationIcon(@Nullable Drawable icon) { ... }

- 2,107
- 2
- 19
- 26
-
5This is ***hiding*** not ***disabling***. The 2 terms are totally different in this context. Disabling means it's just temporarily unavailable for some reason but will available later. I really don't understand the design of Android, it's too much complicated, even something really simple like this makes we do many hacks. I must say that it's just a bad design. Programmers ***mainly*** need to concentrate on business logic, not all these trifles which should have been prepared/provided easily by the Android core libraries writers. – King King Oct 22 '16 at 03:09
-
Also the most suitable method to use to disable the Home button is `SupportActionBar.SetHomeButtonEnabled`, however it does nothing. – King King Oct 22 '16 at 03:14
What Alex K has suggested is for the Back button in navigation bar at the bottom of the screen - not Up icon at the top left corner of the screen.
For the ActionBar up icon you need to add this:
getActionBar().setDisplayHomeAsUpEnabled(false);
Also, in your manifest.xml file, you could delete the parent metadata if there is any:
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.ParentActivity" />

- 3,045
- 3
- 17
- 34
-
1it is not working getSupportActionBar().setDisplayHomeAsUpEnabled(false); – Lawrence Gimenez Jan 22 '15 at 03:06
-
-
I dont have that xml snippet. I guess I have to create a theme based on Toolbar to remove that Up button thing – Lawrence Gimenez Jan 22 '15 at 03:10
-
hmm... Ok, last thing: Check if you have this in your manifest file and delete it if you have: android:parentActivityName="SOME_ACTIVITY" – Kasra Jan 22 '15 at 03:12
-
For this issue I believe it is because you are using the navigationIcon
as the attribute to set the icon on the toolbar
.
<item name="navigationIcon">@drawable/tool_bar_title_logo</item>
When using navigationIcon
as an attribute to set the toolbar
icon:
supportActionBar?.setDisplayHomeAsUpEnabled(false) // won't work
It will not be able to turn off the onClick for the icon.
Instead, use setIcon(R.drawable.tool_bar_title_icon)
to set icon for the toolbar
:
supportActionBar?.setIcon(R.drawable.tool_bar_title_logo) // to set the toolbar icon
Then disable it using:
supportActionBar?.setDisplayHomeAsUpEnabled(false)

- 1,265
- 13
- 12
-
This question is 8 years old, I'm surprised why do you even answer this question? – Lawrence Gimenez Mar 10 '23 at 10:05
-
-
Cool thanks! Just checked your answer as the solution since it is the latest. – Lawrence Gimenez Mar 12 '23 at 00:03
Insert this code to the Activity where you want to hide UP button from Toolbar:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove UP button
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
}

- 18,446
- 7
- 48
- 56
I meet the similar question, the empty navigationIcon holder the left space.
use app:contentInsetLeft="0dp"
in the xml of <android.support.v7.widget.Toolbar>
, it fixs

- 2,479
- 3
- 23
- 32
There are two ways in the manifest which cause the Up navigation to appear in the AppBar. As mentioned by @Kasira:
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.ParentActivity" />
And also if the <activity>
tag contains: android:parentActivityName=".activity.ParentActivtyName"

- 645
- 1
- 5
- 11
I did a lot of searching online but I could not find any solution to this problem. So, I poked around in the source code a little bit and came to this solution:
val field = Class.forName("androidx.appcompat.widget.Toolbar").getDeclaredField("mNavButtonView")
field.isAccessible = true
val toolbarUpButton = field.get(findViewById(R.id.main_toolbar)) as? ImageButton
toolbarUpButton?.isEnabled = false
This does not hide the up button but disables it and if you want to indicate that the button is disabled you can use the following selector as the color for your drawable:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/enabled" android:state_enabled="true"/>
<item android:color="@color/disabled" android:state_enabled="false"/>
<item android:color="@color/enabled" />
</selector>

- 111
- 1
- 2
- 11