Android How can I set an item in the toolbar to fill all the free space?

I tried to assign the scales, of course, but it doesn't seem to be supported by the toolbar.

+4
source share
2 answers

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

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

So your code could 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 code as well -

toolbar.setContentInsetsAbsolute(0,0);

Even you can change it in style -

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

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

LinearLayout . LinearLayout , , layout_weight.

:

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

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

All Articles