Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:fitsSystemWindows at runtime

Tags:

android

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?

like image 719
ilyamuromets Avatar asked May 25 '15 13:05

ilyamuromets


1 Answers

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.

like image 95
Milos Fec Avatar answered Nov 07 '22 11:11

Milos Fec