2017-01-17 18 views
0

Google Mapの上にツールバーの背景色を半透明色に設定することはできますか?Androidツールバーで背景色を半透明色に設定

私は二つのことを試してみました:

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"/> 

のJava:

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

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

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#963f51b5"))); 

どれも私はこれが不可能であると思わせるこれは、動作するようには思えませんか?

+0

はXMLでそれを行います。私は今日それをやった。 –

答えて

5

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

結果:あなたが動作するはず示してきたように

enter image description here

+0

ありがとう!これはうまくいくはずですが、テーマに問題があります。ちょうどそれを追加することで、スタイル/ AppTheme.NoActionBar.PopupOverlay @スタイル/ AppTheme.NoActionBar.AppBarOverlay @ 、ツールバーには、それがまだすべきだったよう – Fullhdpixel

+0

は '@スタイル/ AppTheme.PopupOverlay'にテーマを変更する半透明ではありません編集された回答を参照してください – Isaac

+0

問題はまだ繰り返されます:http://i.imgur.com/3THFN6E.png あなたのイメージのように透明でなければなりませんが、私のアプリではまだ上に白いレイヤーが表示されますあなたが示したテーマのいずれか – Fullhdpixel

関連する問題