Translucide/Transparent barre d'état + CoordinatorLayout + Barre + Fragment

J'ai d'installation suivants:

  • Je suis en utilisant AppCompat
  • MainActivity, qui est titulaire d'un fragment et a une barre d'outils, qui se cache lorsque vous faites défiler vers le bas
  • Fragment avec RecyclerView
  • tous les points de vue qui doivent s'adapter à l'écran ont la fonction android:fitsSystemWindows="true" dans le fichier xml du layout

Le problème est, je ne peux pas obtenir la barre d'état transparente dans ce cas. Ce que je fais est la suivante:

  1. Créer de l'activité et de l'appel setContent
  2. Alors j'essaie d'adapter l'activité de programmation pour obtenir un translucides de la barre d'outils comme suit:

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void themeNavAndStatusBar(Activity activity)
    {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return;
    
        Window w = activity.getWindow();
        w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        w.setFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        w.setFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        w.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
    
        w.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
    }
  3. Remplacez l'espace réservé à l'activité (@+id/frame_container) avec le fragment

La barre de statut est solide de couleur dans ce cas, et les points de vue ne sont pas établis en dessous... Pourquoi?

Ce que je veux

Je veux une barre d'outils, qui est un défilement de l'écran et cachant complètement alors que le contenu en dessous de cette barre d'outils doit fitScreen et être tiré derrière la transparence de la barre de navigation.

Dispositions

Voici mon activité principale:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/clMain"
android:fitsSystemWindows="true"
android:background="?attr/main_background_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:fitsSystemWindows="true"
android:background="@null"
app:elevation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="?actionBarThemeStyle"
app:popupTheme="?actionBarPopupThemeStyle"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivToolbarDataSource"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
android:layout_width="24dp"
android:layout_height="24dp" />
<TextView
android:id="@+id/tvToolbarTitle"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:theme="?actionBarThemeStyle"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/tvToolbarSubTitle"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:theme="?actionBarThemeStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<!-- BUG: http://stackoverflow.com/questions/30541409/coordinatorlayoutappbarlayout-does-not-draw-toolbar-properly -->
<View
android:layout_width="fill_parent"
android:layout_height="1dp"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame_container"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="32dp"
android:src="@drawable/ic_local_offer_white_24dp"
app:backgroundTint="?attr/colorPrimary"
app:borderWidth="0dp"
app:fabSize="normal"
app:rippleColor="?attr/colorPrimaryDark"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="com.test.classes.ScrollAwareFABBehavior"/>
</android.support.design.widget.CoordinatorLayout>

Et voici mon fragment, qui seront placés dans les principaux d'activité:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srlImages"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvImages"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/tvEmpty"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

MODIFIER - les Captures d'écran

- Je utiliser une lumière/obscurité thème de base et de thème tout à la main (parce que l'utilisateur peut sélectionner n'importe quelle couleur primaire/couleur d'accent), il ne faut pas l'esprit que la barre d'outils est blanc (c'est la valeur par défaut du thème de la couleur d'arrière-plan et la couleur primaire). J'ai ajouté une bordure noire en tant que bien de sorte que vous voyez où l'activité se termine...

  • Première Capture d'écran): Affiche la barre d'outils, rien ne défile
  • Seconde Capture d'écran: j'ai juste commencé à scrolling => la barre d'outils maintenant défiler loin
  • Troisième Capture d'écran: le contenu principal doit désormais faire défiler en dessous de la barre de navigation...

En fin de compte, je vais bien sûr faire de la barre d'outils et barre de navigation semi-transparent pour un meilleur effet visuel...

Translucide/Transparent barre d'état + CoordinatorLayout + Barre + Fragment
Translucide/Transparent barre d'état + CoordinatorLayout + Barre + Fragment
Translucide/Transparent barre d'état + CoordinatorLayout + Barre + Fragment

  • Pourriez-vous poster une image? Vous devriez probablement fitsSystemWindows à false pour le CoordinatorLayout (au moins).
  • J'ai ajouté les captures d'écran pour montrer le problème...
  • Ensemble fitsSystemWindows à false pour le CoordinatorLayout et à la frame_container .
InformationsquelleAutor prom85 | 2016-01-13