JanBo
JanBo

Reputation: 2933

Remove left padding on custom action bar

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:

No matter what I do, it still shows up.

Upvotes: 2

Views: 2307

Answers (1)

Felix
Felix

Reputation: 1044

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.

Upvotes: 1

Related Questions