一直在尝试将 Logo 置于工具栏的中央。当我导航到下一个 Activity 时,会出现“向上提示”图标,它会将我的 Logo 稍微向右推。我怎样才能让我的标志保持在工具栏的中央,而不删除向上的启示图标?
这是我的工具栏标签
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
android:paddingTop="@dimen/app_bar_top_padding"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/CustomToolBarTheme">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_android_logo"
android:layout_gravity="center"
android:paddingBottom="3dp"/>
</android.support.v7.widget.Toolbar>
最佳答案
您可以按照对我有用的方式进行操作:
<androidx.appcompat.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="@dimen/abc_action_bar_default_height_material">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/headerLogo"
android:contentDescription="@string/app_name" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
关于android - 如何使 ImageView 在工具栏中居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28443786/