Colin White
Colin White

Reputation: 1116

Android Toolbar width constrained by menu items

Please help! I'm completely stuck and can't find a solution. The useable width of my Toolbar is constrained by the menu items in it. Here's a screenshot. I need to have it not constrained by the menu items so my EditText can span the width of the toolbar. Here is my layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="250sp"
        android:background="@color/primary"
        android:gravity="bottom"
        android:minHeight="?attr/actionBarSize">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button_id"
                android:layout_width="40sp"
                android:layout_height="40sp"
                android:layout_gravity="center" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/url"
                    android:textColor="@color/accent"
                    android:textSize="16sp" />

                <EditText
                    android:id="@+id/url_text_field_id"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textNoSuggestions"
                    android:maxLines="1" />

                <TextView
                    android:id="@+id/output_text_view_id"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/initial_output_text_id"
                    android:textSize="16sp" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.Toolbar>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

Upvotes: 0

Views: 1435

Answers (1)

darnmason
darnmason

Reputation: 2732

Looks like content padding. Here's an existing answered question on the subject: Android API 21 Toolbar Padding

Solution seems to be app:contentStart xml attribute on the Toolbar view. I assume contentEnd exists too.

Upvotes: 1

Related Questions