如何使用菜单项在工具栏中心对齐内容

时间:2017-03-02 10:23:30

标签: android android-toolbar

我在Toolbar中有一个居中的观点。当我添加MenuItem时,内容会被推送,因此它不会居中。我知道ActionMenuView是一个选项,但SearchView这次不会扩展(另一个问题)。我尝试了contentInset属性,但没有运气。

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:gravity="center"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FF0000">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="4dp"
            app:srcCompat="@drawable/ic_ugurlogo_white" />

    </FrameLayout>

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

结果如下。红色视图是FrameLayout。我希望FrameLayout匹配Toolbar宽度。

Toolbar

我将如何实现这一目标?

0 个答案:

没有答案
相关问题