【发布时间】:2017-12-20 18:29:18
【问题描述】:
我在我的应用程序中使用工具栏而不是 actionabar。工具栏工作正常,但问题是我希望应用程序徽标出现在工具栏的中心。如果没有菜单项显示,图像将在中心工具栏,但如果我将搜索或刷新菜单项添加到工具栏,图像也会发生变化。我希望工具栏始终位于中心
代码
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/pink"
android:minHeight="56dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:id="@+id/rl_toolbar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/tv_home_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/image"
android:drawablePadding="10dp"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
【问题讨论】:
-
只需在相对布局中手动添加您的项目。无需使用默认按钮。它非常简单,您可以使用工具栏视图做任何事情。
-
但我需要溢出弹出窗口
-
@ArchanaVetkar 如果需要,您可以制作自己的溢出菜单。这只是一个简单的
dialog包含一个ListView。老实说,你可能会做得更好。 -
是的,您可以像这样制作自定义视图。只需要一点点搜索。