2014-10-25 18 views
18

Ich würde gerne wissen, wenn jemand weiß, wie man eine Aktivität mit transparenter Aktionsleiste, , wie die, die Sie im neuen Google Play Store haben, wenn Sie auf die Seite einer App gehen.Material Design Transparent ActionBar

Ich interessiere mich nicht für das Scrollen und Drehen von transparenten in einfarbigen Hintergrund, Ich brauche nur die Aktionsleiste transparent.

Danke.

Antwort

19

Sie müssen nur <item name="colorPrimary">@android:color/transparent</item> setzen und windowActionBarOverlay auf true auf Ihrem App Thema wie folgt festgelegt:

final result of code

+0

Große, hat es funktioniert. Aber, wie Sie hier sehen: https://fbcdn-sphotos-fa.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/10629709_805789872797492_6827913796269231038_n.jpg?oh=ac43335ed7c387f8c6ed10edfd1faa0f&oe=54B0A62D&__gda__=1420431431_2dfb271b8cb28aee5df2b805507d7e5e Es ist ein bisschen schwarz an der Spitze ... kannst du mir sagen, wie es geht? – user3184899

+0

vielleicht kann Ihnen das helfen http://stackoverflow.com/questions/17801289/android-translucent-background-with-shadow –

29
<item name="colorPrimary">@android:color/transparent</item> 

dieses:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light"> 
     <item name="android:textColorPrimary">@color/my_text_color</item> 
     <item name="colorPrimary">@android:color/transparent</item> 
     <item name="windowActionBarOverlay">true</item> 
    </style> 

</resources> 

Endergebnis sollte wie folgt aussehen oben wird eine Ausnahme auf Lollipop-Geräten resultieren. colorPrimary muss undurchsichtig sein.

Stilvolle Ihre ActionBar mit Stil:

<style name="ThemeActionBar" 
     parent="Widget.AppCompat.Light.ActionBar.Solid"> 
     <item name="android:background">@null</item> 
     <!-- Support library compatibility --> 
     <item name="background">@null</item> 
</style> 

Und in Ihrem Thema, geben Sie einfach:

<item name="android:actionBarStyle">@style/ThemeActionBar</item> 
<item name="android:windowActionBarOverlay">true</item> 
<!-- Support library compatibility --> 
<item name="actionBarStyle">@style/ThemeActionBar</item> 
<item name="windowActionBarOverlay">true</item> 
+3

Wenn Sie wollen, Tönung (dh Transluzenz), anstelle von '@ null 'als Hintergrund (was in voller ergibt Transparenz), verwenden Sie Farbe mit Alpha-Wert wie '# 30000000' – rpattabi

2

Es gibt auch so, wie es pragmatisch zu tun.

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 
mActionBar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
mActionBar.setElevation(0); 
+0

funktioniert nicht für mich – susemi99

+1

Es funktioniert. Füge getWindow() hinzu. RequestFeature (Window.FEATURE_ACTION_BAR_OVERLAY); vor super.onCreate (savedInstanceState); –

2

1) Stellen Sie AppBarLayout Höhen Eigenschaft auf 0dp.

app: Elevations = "0DP"

2) Set Toolbar Hintergrundfarbe zu transparent.

android: background = "@ android: Farbe/transparent"

Whole xml wie unten aussehen:

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay" 
    app:elevation="0dp"> 

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

     ...... 

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

enter image description here

+1

Das funktioniert nicht –

6

Transparent ActionBar

Werte/styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
... 
</style> 

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme"> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="colorPrimary">@android:color/transparent</item> 
</style> 

<style name="AppTheme.ActionBar" parent="AppTheme"> 
    <item name="windowActionBarOverlay">false</item> 
    <item name="colorPrimary">@color/default_yellow</item> 
</style> 

Werte-v21/styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    ... 
</style> 

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme"> 
    <item name="colorPrimary">@android:color/transparent</item> 
</style> 

<style name="AppTheme.ActionBar" parent="AppTheme"> 
    <item name="colorPrimaryDark">@color/bg_colorPrimaryDark</item> 
    <item name="colorPrimary">@color/default_yellow</item> 
</style> 

nutzen diese Themen in Ihrem AndroidManifest.xml festlegen, welche Aktivitäten einen transparenten oder farbigen ActionBar haben

<activity 
      android:name=".MyTransparentActionbarActivity" 
      android:theme="@style/AppTheme.ActionBar.Transparent"/> 

    <activity 
      android:name=".MyColoredActionbarActivity" 
      android:theme="@style/AppTheme.ActionBar"/> 
+0

Schön, danke. :) – Denees

+0

Das ist toll, ich hoffe deine Antwort wird akzeptiert – newbie