Sam Stern
Sam Stern

Reputation: 25134

Overflow menu changes custom Toolbar layout

I have an Activity with a custom Toolbar:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/AppTheme"
        app:contentInsetStart="0dp"
        app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="8dp"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:paddingTop="8dp">

    < !-- More content, including search box -->

      </RelativeLayout>

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

It looks like this in the preview:

enter image description here

But it looks like this on the device:

enter image description here

It seems like the overflow menu is changing the layout. Is there any way around this?

Upvotes: 0

Views: 37

Answers (1)

Sam Stern
Sam Stern

Reputation: 25134

Seems like some similar questions have been asked without an answer: How to properly add custom view to the toolbar?

Instead I just put the search view below the toolbar, not within it. I matched the background colors.

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:theme="@style/AppTheme"
        app:logo="@drawable/ic_restaurant_white_24px"
        app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"
        app:title="@string/app_name"
        app:titleMarginStart="24dp"
        app:titleTextColor="@android:color/white">

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

    <FrameLayout
        android:id="@+id/filter_bar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="?attr/colorPrimary"
        android:padding="12dp">

Upvotes: 1

Related Questions