簡體   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