繁体   English   中英

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

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

这是一个例子

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

尝试这个:
如果需要,请更改填充。

    <?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>

希望这会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM