Skip to content Skip to sidebar Skip to footer

Android - Activity Home/up Arrow Has Additional Padding/margin With Sdk 24

I've just updated my app from using SDK 23 to SDK 24. A problem has arisen for my activities that have show the Up/Home arrow (i.e., getSupportActionBar().setDisplayHomeAsUpEnabled

Solution 1:

This was answered in the Android Issues Tracker. The link is:

https://code.google.com/p/android/issues/detail?id=213826

Add app:contentInsetStartWithNavigation="0dp" to the toolbar view.

Solution 2:

I think that this padding is a new standard to match Material spec in SDK 24. First you must hide default toolbar title by this code:

getSupportActionBar().setDisplayShowTitleEnabled(false);

Then make a file called toolbar.xml and add these codes in that file:

<android.support.v7.widget.Toolbarxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="56dp"android:background="@color/primary_color"app:theme="@style/ThemeOverlay.AppCompat"app:popupTheme="@style/ThemeOverlay.AppCompat.Light"app:contentInsetStartWithNavigation="0dp"><TextViewandroid:id="@+id/toolbar_title"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginLeft="16dp" <!--Addmargin-->
        android:layout_marginStart="16dp"
        android:gravity="left|center"
        android:text="Toolbar Title" <!-- Your title text -->
        android:textColor="@color/white" <!-- Matches default title styles -->
        android:textSize="20sp"
        android:fontFamily="sans-serif-medium"/>

</android.support.v7.widget.Toolbar>

As you see, you can control everything in this file. Look at this line in toolbar.xml :

app:contentInsetStartWithNavigation="0dp"

This is what you want. Goodluck.

Solution 3:

try this code to remove unwanted space use it according to your use :-

<android.support.v7.widget.Toolbar   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/red"
    android:contentInsetLeft="0dp"
    android:contentInsetStart="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:contentInsetRight="0dp"
    android:contentInsetEnd="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp"
    android:minHeight="?attr/actionBarSize">
 </android.support.v7.widget.Toolbar>

Post a Comment for "Android - Activity Home/up Arrow Has Additional Padding/margin With Sdk 24"