2

I am having an issue with the Android v7 support toolbar. When I activate the home as up button and showing it (see Java code below), there is an extra padding for the content of the toolbar which is an Image view. I would like to remove the Imageview left extra padding.

I already tried the attributes, nothing changed:

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

Notice that when I use these attributes without the home as up, it works and there is no padding.

XML:

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="?attr/toolbarBackground"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            android:contentInsetLeft="0dp"
            android:contentInsetStart="0dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icn_photo"
                android:padding="0dp"/>

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

JAVA:

setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);

Result: Toolbar content extra left padding

How could I solve my problem?

Edit This question is different from Android API 21 Toolbar Padding because in my case I need to conserve the home as up (back) button.

Community
  • 1
  • 1
Aïssa-H
  • 97
  • 2
  • 8

1 Answers1

1

Can you try

  1. app:contentInsetStartWithNavigation="0dp"

2.

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
actionBar.setCustomView(customView);
Toolbar parent =(Toolbar) customView.getParent();
parent.setContentInsetsAbsolute(0,0);

3. Make your imageView padding or margin less than 0? e.g. -16dp etc.

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100