2016-06-19 15 views
0

以下のコードを使用して、アクティビティにアクションバーを表示します。しかし、アクションバーの背景は透明ではありません。私はアクションバーの背景を透明にする方法についていくつかの記事を検索しましたが、それは私のためにはうまくいかないようです。私は以下のようにすべてのレイアウトとテーマコードを添付しました。私がここで紛失しているものを確認するのを助けてください。以下はアクションバーの透明な背景を設定するには

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.scanner_activity); 

    Toolbar toolBar = (Toolbar)findViewById(R.id.scanner_toolbar); 
    toolBar.setTitle("Title"); 
    setSupportActionBar(toolBar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
} 

活動のレイアウトxmlファイルである:以下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<android.support.v7.widget.Toolbar 
    android:id="@+id/scanner_toolbar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    android:background="@android:color/transparent" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:theme="@style/AppScannerToolBarTheme" 
    /> 

<com.journeyapps.barcodescanner.DecoratedBarcodeView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_below="@+id/scanner_toolbar" 
    android:layout_alignParentBottom="true" 
    android:id="@+id/zxing_barcode_scanner" 
    app:zxing_use_texture_view="true"/> 


</RelativeLayout> 

ツールバーためAppScannerToolBarThemeです:

<style name="AppScannerToolBarTheme" parent="Theme.AppCompat.Light"> 
    <item name="colorPrimary">@android:color/transparent</item> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="android:windowActionBarOverlay">true</item> 
    <item name="android:backgroundStacked">@android:color/transparent</item> 
    <item name="android:background">@android:color/transparent</item> 
</style> 

はEDIT:

私はコードの下に追加それてきましたまだ動作しません:

画像の下
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
toolBar.setAlpha(0.5f); 
toolBar.setBackground(new ColorDrawable(Color.TRANSPARENT)); 

私が達成したいものです。

enter image description here

答えて

0

ツールバーが表示され、あなたはビュークラスからアルファメソッドを使用することができます。

toolbar.setAlpha(0.5f); 
+0

これは、ツールバーのテキストアルファのみです。私はtoolBar.setBackground(新しいColorDrawable(Color.TRANSPARENT))を使用しようとしました。それは動作しません –

1
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000"))); 

OR

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

これはあなたのためのおかげで働くことを願っています。

+0

私はこのコードを追加しましたが、それでも動作しません –

+0

アンドロイドのアクションバーの新しい色を設定するとアンドロイドが色をスタックするようです。したがって、これはアクティビティスタックのすぐ下のアクティビティのコンテンツを表示するので、透明なアクションバーを設定するのは非常に論理的ではないようです。 – erluxman

+0

スタックを変更するにはどうしたらいいですか、アクションバーを透明にする方法はありますか? –

関連する問題