0

我有一个工具栏,我想在活动中在此工具栏之间切换时更改背景图像。此外,工具栏是固定的并包含在 <include> 中。

layout_toolbar.xml

<android.support.v7.widget.Toolbar 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:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@drawable/ic_customer_toolbar"
    android:gravity="center"
    app:navigationIcon="@drawable/ic_left_arrow"
    app:popupTheme="@style/AppTheme.PopupOverlay">




    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <RelativeLayout
            android:id="@+id/linearLayoutToolbarContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:paddingEnd="75dp"
            android:paddingRight="75dp"
            tools:ignore="Orientation">

            <TextView
                android:id="@+id/textViewSectionTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:fontFamily="@font/roboto_regular"
                android:gravity="center"
                android:textAlignment="center"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold"
                android:visibility="gone"
                tools:text="Section Title" />

        </RelativeLayout>


        <ProgressBar
            android:id="@+id/toolbarProgressbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:padding="@dimen/app_padding_tiny"
            android:visibility="invisible" />

        <Button
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginEnd="22dp"
            android:background="@drawable/ic_menu_button" />
    </RelativeLayout>


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

和我的

activity_customer.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.design.widget.AppBarLayout
        android:id="@+id/appbarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@drawable/ic_tabview"
            app:tabGravity="fill"
            app:tabIndicatorHeight="4dp"
            app:tabMode="scrollable"
            app:tabTextAppearance="@style/TabLayoutTextStyle"
            app:tabTextColor="@color/textmavi"
            app:theme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbarLayout">

    </android.support.v4.view.ViewPager>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/editCustomerButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="16dp"
        android:clickable="true"
        app:srcCompat="@drawable/ic_icon_edit"
        tools:ignore="VectorDrawableCompat" />
</RelativeLayout>

我有一个像这样的activity_sale.xml 文件,我希望它与activity_customer 工具栏的工具栏颜色不同。我怎样才能做到这一点?

4

0 回答 0