1

On my main activity, where there is no way to go back, I'd like to remove the app "home" button in the actionbar.

I think it is confusing for the user, who still can quit the app with the OS back button.

Browsing stackoverflow, I saw a whole lot of people asking this, and not a single answer worked for me. Here is the list :

The answers were usually redondant and could be summarized to following :

ActionBar supportActionBar = getSupportActionBar(); //I target some low API
if(supportActionBar != null) {
    supportActionBar.setDisplayShowHomeEnabled(false);
    supportActionBar.setDisplayHomeAsUpEnabled(false);
    supportActionBar.setHomeButtonEnabled(false);
    supportActionBar.setHomeAsUpIndicator(null);
}

I tried every combination of those and nothing worked, whether I try with the default ActionBar or with an XML-declared compat-v7 ToolBar with setSupportActionBar().

I also couldn't see any question adapted for the now recommanded App Bar, and an answer with it would be even greater.

Here is my activity manifest :

<activity
    android:name=".activity.WelcomeActivity"
    android:logo="@drawable/ic_launcher"
    android:label="@string/long_app_name"
    android:launchMode="singleTop"/>

So, is it even possible to remove this annoying useless arrow nowadays ?

Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92
  • Where is your action bar coming from? Are you using a `Toolbar` and calling `setSupportActionBar()` or are you just using the default action bar from themes? What does the manifest entry for your activity look like? – Ben P. Nov 14 '17 at 17:55
  • I tried both using the default `ActionBar` and setting an App Bar in my XML (with a `NoActionBar` theme in the manifest) – Dan Chaltiel Nov 14 '17 at 20:02
  • are you using custom action bar theme or custom app theme? – Atif Farrukh Nov 15 '17 at 08:10

2 Answers2

1

Create a new style in styles.xml:

 <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

Set this style to your activity in Manifest file. To add the Toolbar, add this to your layout file:

<android.support.v7.widget.Toolbar
        android:background="@color/colorPrimary"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.Toolbar>

and then in your Java class:

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

This will remove the top left arrow.

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42
  • Did you try this yourself ? It don't work for me (top left arrow is still there) but I really wonder whether the fault is on my side or not. (also I think you mistook the id :-) ) – Dan Chaltiel Nov 15 '17 at 08:00
  • 1
    OK, it was because of the XML-declared theme of the Toolbar. Works fine now, thanks ! – Dan Chaltiel Nov 15 '17 at 22:35
-1

simply put getSupportActionBar().setDisplayHomeAsUpEnabled(false)in onCreate of the activity.