【问题标题】:Android actionbar title - change background colorAndroid 操作栏标题 - 更改背景颜色
【发布时间】:2016-05-01 12:58:48
【问题描述】:

在顶部的 Android 工具栏中,我在背景上使用渐变色。它工作得很好,但我注意到标题被包裹在继承另一种渐变颜色的东西中。如何将标题的背景改为透明?

<style name="Toolbar" parent="@style/ThemeOverlay.AppCompat.ActionBar">
    <item name="android:background">@drawable/toolbar_gradient</item>
</style>


<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:elevation="4dp"
    app:titleTextColor="@color/white"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/Toolbar"/>

[..[ x ] ... y ]

所以容器 x 包裹了标题,并且具有从工具栏 y 突出的背景颜色。

【问题讨论】:

    标签: android


    【解决方案1】:

    添加带有标题的自定义工具栏。

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="4dp"
        app:titleTextColor="@color/white"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/Toolbar">
    <TextView android:id="@+id/footer" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textSize="25sp"
            android:singleLine="true" android:background="#07000000"
            android:textColor="#FFFFFF" android:text="rrrrr"
            android:layout_centerInParent="true"
            android:layout_alignParentBottom="true" />// set your background as you wish
    </android.support.v7.widget.Toolbar>
    

    【讨论】:

    • 啊,这样的想法!干得好,谢谢!