2017-11-21 8 views
2

私は主なアクティビティに3つのタブを持つアプリケーションで作業しています。 2番目のタブのフラグメントには、ヘッダー付きのNestedScrollViewがあり、これをシステムウィンドウに合わせる必要があります。タブの残りの部分は、ツールバーを使って正常に表示されます。現在のタブが2番目の場合はsetFitsSystemWindows(true)に設定し、それ以外の場合はfalseに設定します。それは最初の実行(最初のタブで)に続いて2番目のタブに移動しますが、1番目のタブに戻るとバグが発生します。 1番目のタブに戻るとツールバーがシステムウィンドウに合ったときにfalseに設定されているようです。以下This is the screenshot of the toolbar when going back to 1st tabfitSystemWindowsはタブの1つのフラグメントにのみ適用されます

私MainActivityのXMLコードです:タブを切り替えたとき、私はこのようなsetFitsSystemWindowsにブール値を設定するコードで

<?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:id="@+id/rootLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     app:elevation="0dp"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:contentInsetStart="0dp" 
      app:navigationIcon="@drawable/ic_search" 
      app:title="Our Menu" /> 

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

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <au.com.appetiser.youfoodz.widgets.bottom_navigation.BottomNavigationLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:orientation="vertical" 
     app:layout_behavior="au.com.appetiser.youfoodz.view.GenericBottomBehavior"> 

     <android.support.design.widget.BottomNavigationView 
      android:id="@+id/navigation" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_gravity="bottom" 
      android:background="@android:color/white" 
      app:elevation="0dp"/> 
    </au.com.appetiser.youfoodz.widgets.bottom_navigation.BottomNavigationLayout> 

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

@Override 
    public void onTabTransaction(Fragment currentFragment, int i) { 
    rootLayout.setFitsSystemWindows(currentFragment instanceof SecondFragment); 
    } 
+0

あなたがこれまでにやっていること、あなたのコードを投稿しますか?だから我々は助けることができる –

+0

@rajanksありがとう男。上記の質問を更新しました:) – kebbbnnn

答えて

0

試行錯誤最終的に私の週間後問題を解決しました。それは汚い回避策ですが、そのことが完了しました。私はCoordinatorLayoutの上にFrameLayoutの親を追加しました。 android:fitsSystemWindows="true"CoordinatorLayoutAppBarLayoutに設定しました。そしてonTabTransactionにのfitsSystemWindowsfalserootLayoutの代わりにCoordinatorLayoutと設定しました。

のxml:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    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.support.design.widget.CoordinatorLayout 
     android:id="@+id/rootLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:background="@android:color/white"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      android:background="@android:color/transparent" 
      app:elevation="0dp"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:contentInsetStart="0dp" 
       app:navigationIcon="@drawable/ic_search" 
       app:title="Our Menu"/> 

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

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

     <au.com.appetiser.youfoodz.widgets.bottom_navigation.BottomNavigationLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:orientation="vertical" 
      app:layout_behavior="au.com.appetiser.youfoodz.view.GenericBottomBehavior"> 

      <android.support.design.widget.BottomNavigationView 
       android:id="@+id/navigation" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_gravity="bottom" 
       android:background="@android:color/white" 
       app:elevation="0dp"/> 
     </au.com.appetiser.youfoodz.widgets.bottom_navigation.BottomNavigationLayout> 

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

Javaコード:

@Override 
    public void onTabTransaction(Fragment currentFragment, int i) { 
    appBarLayout.setFitsSystemWindows(currentFragment instanceof SecondFragment); 
    } 

出力:

enter image description here

関連する問題