Android工具栏将背景颜色设置为半透明颜色

Ful*_*xel 0 java android

是否可以在Google地图上设置工具栏背景颜色为半透明颜色.

我尝试了两件事:

XML:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#963f51b5"
    app:popupTheme="@style/AppTheme.PopupOverlay"/>
Run Code Online (Sandbox Code Playgroud)

Java的:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);
getSupportActionBar().setTitle(distanceText);

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#963f51b5")));
Run Code Online (Sandbox Code Playgroud)

似乎没有工作,这让我觉得这是不可能的?

Isa*_*aac 6

如果您将背景设置AppBarLayout为透明,它应该可以工作.

例如:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/content_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!--Add the rest of your views in here-->
    </LinearLayout>

    <!--Needs to be at the bottom so it's shown over all the other views-->
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#963f51b5"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
</RelativeLayout>>
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述