0

シンプルなCollapsingToolbarLayoutがあります。すべてが正常に動作し、期待通りにステータスバーは、ここでは、ページをスクロールする前に、(透明)透明である:CollapsingToolbarLayoutがフラグメント内にあるときに透明なステータスバーを表示できません。

screenshot of normal behavior

問題は、私はactivity_main.xmlから、CoordinatorLayoutタグとCollapsingToolbarLayoutを含み、そのコンテンツを転送する際に現れますフラグメント、ステータスバーはもはや透明ではありません!なぜ?!私は、コードの一部をコピーし、(もはや透明ではない)ここの断片でそれを貼り付け、コードのどの部分を変更していない:

screenshot of status bar which is not transparent anymore

ここではコードです:

MainActivity.javaが

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <FrameLayout 
     android:id="@+id/main_fragment" 
     android:fitsSystemWindows="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </FrameLayout> 

</android.support.v4.widget.DrawerLayout> 

activity_main.xml

public class MainActivity extends AppCompatActivity implements TestFragment.OnFragmentInteractionListener {  
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

      if (savedInstanceState == null) { 
      getSupportFragmentManager().beginTransaction() 
        .add(R.id.main_fragment, new TestFragment()) 
        .commit(); 
     } 

    } 

} 

fragment_test.xml

<android.support.design.widget.CoordinatorLayout  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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".TestFragment"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="256dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      app:contentScrim="@color/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      > 

      <ImageView 
       app:layout_collapseMode="pin" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/toolbar_bg" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       app:layout_collapseMode="pin" 
       app:layout_scrollFlags="scroll|enterAlways" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:popupTheme="@style/AppTheme.PopupOverlay" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

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

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

    <android.support.v4.widget.NestedScrollView 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="fill_vertical" 
     app:behavior_overlapTop="32dp" 
     android:background="@color/main_bg"> 


    </android.support.v4.widget.NestedScrollView> 


    <android.support.design.widget.FloatingActionButton 
     app:fabSize="normal" 
     app:layout_anchor="@id/appbar" 
     app:layout_anchorGravity="bottom|right" 
     app:srcCompat="@drawable/ic_add_black_24dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:onClick="FABTouched" 
     android:tint="@color/main_bg" 
     /> 

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

のstyles.xml CoordinatorLayoutへ

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

答えて

0

変更でframeLayout。

+0

それは働いた。ありがとうございました – Sab

関連する問題