0

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?

1
  • Have you tried setting the SearchView Maxwidth to (Integer.MAX_VALUE)? Commented Aug 24, 2017 at 5:49

1 Answer 1

1

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">
Sign up to request clarification or add additional context in comments.

1 Comment

Using an AppBarLayout would be another solution - would come in handy if you want to hide either the title or search once the user stars scrolling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.