0

Ich habe eine Navigationsschublade Vorlage. Ich habe die Aktionsleiste so geändert, dass ich den Titel nicht sehen kann. Und ich weiß, wie die Farben zu ändern, aber ich weiß nicht, wie diese Wirkung zu erhalten:Android Studio - Transparente Aktionsleiste - Navigationsschublade

enter image description here

Das ist mein aktueller Status:

enter image description here

Das ist mein styles.xml (was teme ich verwende):

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

Antwort

0

Sie können Toolbar mit transparentem Hintergrund verwenden.

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/your_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#4BAE4F" 
     android:orientation="vertical"> 

     <!--Place your content here--> 

    </LinearLayout> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@android:color/transparent" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

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

</RelativeLayout> 

MainActivity.java:

public class MainActivity extends AppCompatActivity { 

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

     setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); 
    } 
} 

styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 

    </style> 

Von API 19 aus können Sie den Parameter <item name="android:windowTranslucentStatus">true</item> in Ihrer styles.xml setzen, um die Statusleiste ebenfalls transparent zu machen.

+0

Ich habe versucht, aber die App stürzt ab. Gibt es eine andere Möglichkeit, diesen Effekt zu erzielen, oder muss ich die gesamte App neu starten? – Ivan

+0

überprüfen Sie die Logcat-Ausgabe, um den Grund des Absturzes zu erfahren. Stellen Sie außerdem sicher, dass Sie das übergeordnete Element Ihres AppTheme auf "Theme.AppCompat.Light.NoActionBar" festlegen. – dzikovskyy

Verwandte Themen