24

I want to remove the left arrow from the action bar and only icon and title needed.

My code:

getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.dashboardtitle);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);

But this doesn't remove the left arrow . Any help!!

Renjith
  • 5,783
  • 9
  • 31
  • 42
info
  • 2,152
  • 5
  • 22
  • 38

5 Answers5

26

According to specification android specification: To enable the icon for up navigation (which displays the "up" indicator next to the icon), call setDisplayHomeAsUpEnabled(true) on your ActionBar:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    ...
}

So you should set actionBar.setDisplayHomeAsUpEnabled(false);

UPDATE: I test next code with ActionBar sherlock and it's work. There is no back arrow:

getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.about_event_location);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Borys
  • 1,793
  • 2
  • 17
  • 32
22

You need to add this to your actionBar theme. You can replace arrow image with your own image which can be transparent

<item name="android:homeAsUpIndicator">@drawable/action_arrow</item>
vivek
  • 4,599
  • 3
  • 25
  • 37
  • 4
    This worked! I had to set the new drawable to a transparent image of some width, since using `@android:color/transparent` does not include any padding to the left of the app's icon. –  Jul 23 '13 at 11:04
  • It's possible to use @null to avoid create a transparent image resource. @null – Guilherme Muniz Apr 09 '15 at 19:18
3
getActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);

Where action_arrow is a 25x10px transparent png. Same code for sherlock would be:

getSupportActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
xip
  • 2,475
  • 3
  • 18
  • 24
1

@vivek: works great. I do not recommend to use @android:color/transparent as Tim Cooper said, because the Title is aligned to the left. So a empty image is better

defim
  • 456
  • 6
  • 9
0

In AndroidManifest.xml

remove the below code, which will remove back button from your ActionBar

android:parentActivityName=".Main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main.MainActivity" />

Just keep it like below:

<activity
android:name=".YourActivity"
android:label="@string/your_activity_label">
</activity>
Keshav
  • 2,965
  • 3
  • 25
  • 30
  • I ran into the ugly back arrow issue precisely because I had to add the android:parentActivityName attribute in order to build a proper back stack! Your solution can also break the desired behavior of the system's back button. – Pat Lee Nov 04 '20 at 10:10