I am trying to add a custom image as the action bar logo, which works, however, there is about 30-50dp of padding in front of this image when it is added to the action bar.
The image itself has no padding on the left, so it should be almost right next to the edge of the screen.
Where does this padding get added from at runtime? Here is my code for the custom layout I am using for the actionbar:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/actionbar">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/logo"
</RelativeLayout>
This is my code for setting up the action bar layout in my activity:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.actionbar, null);
actionBar.setCustomView(v);
The only way I have found to remove this padding is by adding android:layout_marginLeft="-30dp"
to the layout of the custom action bar, but I definitely don't think this is the correct approach.
Any ideas why there would be extra padding in from of my image? Thanks in advance for the help!
EDIT
I managed to figure this out, I added the following two lines to my action bar setup in my activity:
Toolbar parent = (Toolbar) v.getParent();
parent.setContentInsetsAbsolute(0, 0);