Search code examples
androidandroid-toolbar

How to properly add Custom View in toolbar?


I am adding a custom view in toolbar but it is not using full toolbar width it gives space from left side.

code snippet

<android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorPrimary">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

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

getting view from this code snippet

Can anyone please tell me Why it is not using full width of toolbar?

enter image description here


Solution

  • Add these 4 attributes in your toolbar it should help you override that effect.

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

    Do let me know if this was of any help.