简体   繁体   中英

Android transparent status bar and custom view insets

I want to draw my layout behind transparent status bar. I'm using conductor's controllers for implementing my app's screens, all of them have white status bar but one need it to be fully transparent. I can't use windowTranslucentStatus flag when entering this controller because it causes my layouts to jump a little bit when controller enters and exists the screen. I think that custom window insets could help to have one controller to be drawn behind status bar without layout's jumping but I can't figure out how to it. Could anyone help me with this please?

Use android:fitsSystemWindows="true" in the root view of your layout.

What does fitsSystemWindows do?

System windows are the parts of the screen where the system is drawing either non-interactive (in the case of the status bar) or interactive (in the case of the navigation bar) content. Most of the time, your app won't need to draw under the status bar or the navigation bar, but if you do: you need to make sure interactive elements (like buttons) aren't hidden underneath them. That's what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don't overlay the system windows.

Source

To do that I would recommend you to hide the status bar and enable full screen window . Try below, it works.

Step 1: Create theme in style.xml

<style name="FullScreen" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Step 2: Apply the theme for activity in manifest file, can also apply theme at the application level too. For example have added in activity level.

<activity
    android:name=".MainActivity"
    android:theme="@style/FullScreen" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM