I have an app that uses fitsSystemWindows to be able to draw an background behind Navigation- and Status-Bar - unfortunately the SnackBar seems to ignore the fitsSystemWindows=true from the container. I boiled the problem down to this minimal app:
the style:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@color/accent_material_dark</item>
<item name="android:fitsSystemWindows">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
the activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Snackbar.make(v,"This Snackbar should fitSystemWindows",Snackbar.LENGTH_INDEFINITE).show();
}
});
}
}
Anyone knows some workaround?
I published the minimal app to show the problem here: https://github.com/ligi/SnackBarFitsSystemWindowProblem
fitsSystemWindows = true sets the padding to your view (if needed) to prevent your content from being obscured by the system status bar or navigation bar. Now our screen looks like that: How to avoid content obscure and add necessary paddings? To do so, Android provides WindowInsets.
Snackbar
will always look for a CoordinatorLayout
to anchor itself in: when you don't have one, it uses the full content view (which in your case, includes the area under the status bar) - adding a CoordinatorLayout
that has fitsSystemWindows=true
should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With