Android: fitsSystemWindows and new line interfere with bottomSheets

I found out that if the parent layout contains android:fitsSystemWindows="true" , it will interfere with my positioning of BottomSheets when an action related to viewing occurs.

In particular, the one I come across: where a new line in the text view launches the lower tables to compensate for the height of the / notif -bar system.

newline + fitsSystemWindows = disables my bottom sheet down

I deleted all unnecessary things to buttons, text and bottom sheet.

  • Button2: setText("1\n2") where the magic happens

As soon as I remove android:fitsSystemWindows="true" , everything is fine, no weirder behavior, but I lose the effect of how fitsSystemWindows is colored in the / notif -bar system.

I also tried giving my bottomSheet method my own android:fitsSystemWindows="false" , but it did not affect it.

How can I achieve how fitsSystemWindows = true without this strange offset behavior on my bottom sheets?

See for yourself! enter image description here

 public class Test extends AppCompatActivity { private BottomSheetBehavior bottomSheetBehavior; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_test); LinearLayout bottomSheet = (LinearLayout) findViewById(R.id.root_btmsheet); bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); bottomSheet.post(new Runnable() { @Override public void run() { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } }); ((Button) findViewById(R.id.btn1)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ((TextView) findViewById(R.id.info1)).setText("1"); } }); ((Button) findViewById(R.id.btn2)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // the culprit, Mr. Newline ((TextView) findViewById(R.id.info1)).setText("1\n2"); } }); } } 

act_test.xml

 <?xml version="1.0" encoding="utf-8"?> <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:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" <-- the other culprit, Ms. Fits tools:context=".Test"> <!--<include layout="@layout/act_test_content" />--> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:orientation="vertical" android:id="@+id/root_content"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" /> </LinearLayout> <TextView android:id="@+id/info1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#e0e0e0" /> </LinearLayout> <!--<include layout="@layout/act_test_btmsheet" />--> <LinearLayout android:layout_width="match_parent" android:layout_height="200dp" app:layout_behavior="@string/bottom_sheet_behavior" android:orientation="vertical" app:behavior_hideable="false" app:behavior_peekHeight="50dp" android:background="#5533b5e5" android:id="@+id/root_btmsheet"> </LinearLayout> </android.support.design.widget.CoordinatorLayout> 
+5
source share
1 answer

I also had a similar problem even with library support 25.1.0. But later I realized that this could be due to the fact that CollapsingToolbarLayout was not used. I turned it on and hit it! .. it behaves fine even after changing the layout due to line breaks.

0
source

All Articles