Android – How can I set an item in a Toolbar to fill all of the available space?

You can use the following to get rid of left margin in the tool bar

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

So finally your code can be like this-

<android.support.v7.widget.Toolbar
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        android:layout_width="match_parent"
        android:layout_height="48dp">

        <TextView
            android:id="@+id/progress"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@color/background_floating_material_dark" />
    </android.support.v7.widget.Toolbar>

Edit
You can do in the code also as-

toolbar.setContentInsetsAbsolute(0,0);

Even you can modify it in style too-

<item name="toolbarStyle">@style/Widget.Toolbar</item>

<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>

Leave a Comment