My Android app starts with the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"/>
</RelativeLayout>
Activity have an offset for status bar.
I want to remove this offset at runtime by clicking on the button. By clicking on the button I do the following, but it doesn't work, nothing happens:
findViewById(R.id.root).setFitsSystemWindows(false);
How can I do that?
I have been dealing with this issue and found only this unanswered question.
Finally I've found the solution:
View view = findViewById(R.id.root);
view.setFitsSystemWindows(false);
view.setPadding(0, 0, 0, 0);
Setting fitsSystemWindows to true modifies the padding. Apparently disabling fitsSystemWindows keeps the padding set.
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