2017-09-13 3 views
1

J'essaie de rendre la barre d'outils transparente avec le tiroir de navigation. Il fonctionne bien jusqu'à l'API < 21, mais au-dessus de l'API 21, la barre d'outils n'est pas transparente. J'ai déjà ajouté le thème au dossier de style v-21. Ajout du thème ainsi que de l'image. Api < 21 Barre d'outils transparente avec tiroir de navigation

Api > 21

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 

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

    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="color">@color/colorPrimary</item> 
</style> 

De plus, i ont créé un sélecteur d'arrière-plan pour la barre d'outils et dans lequel les couleurs sont transparentes

xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.mayank.tracar.activties.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    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="@drawable/toolbar_background" 
     /> 

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

<include layout="@layout/content_main" /> 


</android.support.design.widget.CoordinatorLayout> 

styles

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="colorPrimary">@android:color/transparent</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 

    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 

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

    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

Répondre

1

Enfin, je l'ai résolu en changeant ces choses dans mon code. J'espère que cela aidera aussi quelqu'un d'autre.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.mayank.tracar.activties.MainActivity"> 



<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@drawable/toolbar_background" 
    /> 



<include layout="@layout/content_main" /> 

</android.support.design.widget.CoordinatorLayout> 

Si supprimer AppBarLayout alors votre barre d'outils va derrière l'inclure la mise en page, afin de résoudre ce que je viens d'appeler toolbar.bringtoFront() sur mon oncreate Et tout fonctionne bien maintenant.