Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fitsSystemWindows does not work in added fragment

In my app I have an activity. The theme for this activity is normal pre-L but is overriden for L and above, with:

...
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/statusTrans</item>
...

This activity has a layout like this (fsw means that node fitsSystemWindows) to give the Material effect.

CoordinatorLayout (fsw)
  L AppBarLayout (fsw)
      L CollapsingToolbarLayout (fsw)
          L ImageView (fsw)
          L Toolbar
      L TabLayout
  L ViewPager
  L FAB

Thing is, I add a fullscreen DialogFragment via a transaction to this activity, by adding it to android.R.id.content having this layout

CoordinatorLayout (fsw)
  L AppBarLayout (fsw)
      L CollapsingToolbarLayout (fsw)
          L FrameLayout
          L Toolbar
      L TabLayout
  L NestedScrollView

The initial layout draws the statusBar and then the Toolbar below it as expected (ie insets are applied), but the added fragment layout draws the Toolbar directly under the statusBar and I cannot seem to get it to draw right.

I dont know what I'm doing wrong. Heres two screen shots showing the problem.

One Two

.

ALSO (BONUS QUESTION!)

In the same Activity, I set the Viewpager to have a ScrollingViewBehavior. The fragments that populate the Viewpager however have a ViewFlipper which switches out one of these: a loadingView(ProgressBar), contentView(RecyclerView) and emptyView(LinearLayout). This ensures that if theres content, the activity has the desired scrolling effect.

Problem arises with the emptyView because it doesnt center correctly. I've attached an image.

How can I correct (or hack) this behavior?

Three

like image 433
efemoney Avatar asked Oct 31 '22 05:10

efemoney


1 Answers

Wherever your replacing your fragment make sure its in a coordinator layout. For example, if your xml looks like this:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:ignore="MissingPrefix">

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

then wrap that in a coordinatorlayout to resolve the problem.

like image 90
j2emanue Avatar answered Nov 09 '22 07:11

j2emanue