Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Toolbar's Up Button

Tags:

android

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.

enter image description here

like image 463
Lawrence Gimenez Avatar asked Jan 22 '15 02:01

Lawrence Gimenez


People also ask

How do I hide the back button on my toolbar?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How to set Action bar in Android?

To code the elements of ActionBar, create a new directory in the resource folder of the application project files. Right-click on the res folder and selects New -> Directory. Give the name “menu” to the new directory. Further, create a new Menu Resource File by right click on the menu directory.

How to use getSupportActionBar?

To use the ActionBar utility methods, call the activity's getSupportActionBar() method. This method returns a reference to an appcompat ActionBar object. Once you have that reference, you can call any of the ActionBar methods to adjust the app bar. For example, to hide the app bar, call ActionBar.


2 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) { ... }
like image 67
zasadnyy Avatar answered Oct 26 '22 11:10

zasadnyy


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" />
like image 33
Kasra Avatar answered Oct 26 '22 09:10

Kasra