溢出菜单更改自定义工具栏布局

时间:2017-08-24 00:49:57

标签: android android-layout android-appcompat

我有一个自定义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>

在预览中看起来像这样:

enter image description here

但它在设备上看起来像这样:

enter image description here

似乎溢出菜单正在改变布局。有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:1)

似乎有些类似的问题没有得到答案: How to properly add custom view to the 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: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">
相关问题