2

First I know this is a duplicate question, but none of the answers solved my issue.

Here is my current code:

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.action_bar);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);

XML:

    <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal"
android:layout_gravity="fill_horizontal"
android:padding="0dp"
android:layout_margin="0dp"
android:background="@color/article_background">
<ImageButton android:src="@drawable/filter"
    android:layout_width="36dp"
    android:layout_height="36dp"
    android:background="#00000000"
    android:scaleType="centerInside"
    android:id="@+id/filters"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"/>

<ImageView
    android:src="@drawable/tc_logo"
    android:layout_width="36dp"
    android:layout_height="36dp"
    android:scaleType="centerInside"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/logo" />

<ImageButton android:src="@drawable/menu_button"
    android:background="#00000000"
    android:layout_width="36dp"
    android:layout_height="36dp"
    android:scaleType="centerInside"
    android:id="@+id/options"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"/>
  </LinearLayout>

And there is a left padding showing.

I tried the following suggestions from Stack Overflow:

  • I tried setting a custom actionbar style in themes with zero padding.

  • I tried with relative and linear layout as the custom layout.

  • I tried setting custom actionbar icon in themes and enabling onHomeUp to display a one px image..

  • I tried layout gravity and gravity to fill_horizontal but didn't work.

No matter what I do, it still shows up.

halfer
  • 19,824
  • 17
  • 99
  • 186
JanBo
  • 2,925
  • 3
  • 23
  • 32
  • I finally went with negative margin of 14 dp....but not the answer still. – JanBo Dec 03 '14 at 11:47
  • I am still facing this issue.Do you have another solution? – Dhaval Khant Dec 05 '14 at 11:44
  • Unfortunately no...stack is full of various answers but for some reason none of them worked for me, neither did combinations of them. I did find that this hack od -14dp margin when set in styles.xml works across all devices, screens, densities...but still i would prefer a normal solution. – JanBo Dec 05 '14 at 14:24

1 Answers1

1

I had the same issue, and nothing helped, until I found this SO question.

TL;DR

  1. Have the Actionbar to display its up arrow, by calling setDisplayHomeAsUpEnabled(true).
  2. Create a style based on your apps theme in "values-v14" (these will apply to SDK Version 14 and above).
  3. have this item in the new style: <item name="android:homeAsUpIndicator">@null</item>. This will cause the up to disappear, but the padding the icon had will be gone.
halfer
  • 19,824
  • 17
  • 99
  • 186
Felix
  • 1,034
  • 1
  • 9
  • 29
  • Interesting i will try this out and let you know if it works. – JanBo Feb 11 '15 at 22:12
  • Nope, didnt work. Event though i put @null for indicator in my action bar style, the arrow is shown. – JanBo Feb 13 '15 at 10:56
  • Merde! Can you post a code digest (Code sample, reproduction or something) to here, or better yet, to GitHub? I'll clone and see what's up... – Felix Feb 15 '15 at 09:37