Android 操作栏:将操作按钮的颜色和标题更改为中心

Android Action Bar: Changing the color of Action Buttons and title to the center

Here an example

这是图片,请问有人可以建议我如何更改图标颜色和标题,使其居中于操作栏...

试试这个:
如果需要,可以更改填充。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="@dimen/abc_action_bar_default_height_material">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1"
        >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_edit"

            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="ABC"
            android:gravity="center"
            android:layout_weight="1"
            android:textColor="@android:color/white"

            />
        <ImageView
            android:layout_width="wrap_content"
            android:paddingRight="10dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_edit"/>
    </LinearLayout>
</android.support.v7.widget.Toolbar>

这样试试

在您的项目中创建新布局custom_toolbar.xml。

在上面的文件中添加以下代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/imgLeft"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="10dp"
        android:src="@drawable/ic_events" />

    <ImageView
        android:id="@+id/imgRight"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_marginRight="10dp"
        android:src="@drawable/ic_action" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="Test"
        android:textColor="@android:color/white"
        android:textSize="25sp" />


</RelativeLayout>

然后将该布局添加到您的工具栏 xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <include layout="@layout/custom_toolbar" />

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

希望对您有所帮助。