【发布时间】:2017-07-14 07:31:34
【问题描述】:
您好,我正在使用工具栏并尝试将徽标设置到操作栏的中心。但是在中间有标题,(我认为)这就是为什么徽标从操作栏的左侧开始。然后我删除了标题以将徽标放在中心,但效果不佳。我该如何解决这个问题?
这是我用来设置工具栏的方法。
private void setToolBar(){
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setBackgroundColor(getResources().getColor(colorActionBar));
toolbar.setLogo(R.drawable.logoactionbar);
}
这是我清单中的主题
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
这里是工具栏的声明
<<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorActionBar"
android:fitsSystemWindows="true"
tools:context="com.anadolusigorta.rhextranet.com.anadolusigorta.rhextranet.HomeActivity">
<View
android:id="@+id/statusBarBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:background="@color/colorActionBar"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorActionBar"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logoactionbar"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_home" />
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
你已经创建了一个自定义工具栏
-
你可能想要使用 ReleativeLayout 而不是 CoordinatorLayout
标签: android xml android-actionbar android-toolbar