Skip to content
Android library for enabling edge-to-edge content and insetting views using simple Kotlin DSL
Kotlin
Branch: master
Clone or download
Latest commit 34601ae Jan 20, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app New Edge.All shortcut edge Jan 7, 2020
buildSrc
gradle/wrapper Initial edge-to-edge implementation Dec 24, 2019
library
.gitignore
CHANGELOG.md New Edge.All shortcut edge Jan 7, 2020
LICENSE Initial commit Dec 24, 2019
README.md Update README.md Jan 20, 2020
build.gradle.kts Add buildSrc Dec 25, 2019
gradle.properties Rename library folder Dec 24, 2019
gradlew
gradlew.bat Initial edge-to-edge implementation Dec 24, 2019
settings.gradle.kts

README.md

Maven Central License

🌖 Edge-to-Edge

In meanwhile, here is an Android library for enabling edge-to-edge content and insetting views using simple Kotlin DSL.

Getting Started

  1. Configure transparent colors of the status and navigation bars in res/values/styles.xml by extending a theme without the action bar like Theme.MaterialComponents.Light.NoActionBar or Theme.Design.Light.NoActionBar or similar.
<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        ...
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentStatus">false</item>
        <item name="android:windowTranslucentNavigation">false</item>
        <item name="android:statusBarColor">@color/statusBar</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
    </style>
    
    <color name="statusBar">@android:color/transparent</color>
    <color name="navigationBar">@android:color/transparent</color>
</resources>
  1. Remove android:fitSystemWindows attribute everywhere from layouts, if present.
  2. Fit top and bottom views of each fragment or activity as needed.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    edgeToEdge {
        appbar.fit { Edge.Left + Edge.Top + Edge.Right }
        recycler.fit { Edge.Bottom }
    }
    ...
}

See sample app for more edge-to-edge examples.

Download

repositories {
    mavenCentral()
}
dependencies {
    implementation 'de.halfbit:edge-to-edge:<version>'
}

How

The library is implemented around WindowInsets class. Each time WindowInsets are dispatched through out the view hierarchy, the library fits views according to the declared fitting rules.

Edge-to-Edge library fits each view to one or more device edges by modifying its padding, margin or height attribute with the values taken from the current WindowInsets. Padding and margin attributes preserve their original values defined in layout and inset values are added to them. The library "auto-detects" the attrbitute to modify, which can be overridden by using fitPadding, fitMargin or fitHeight convenience functions.

Features

  • Easiness of use - padding, margin or height can be adjusted to any edge with a single line of code.
  • Convenient default parameters for common elements like recycler view, scroll view, floating actions button etc.
  • Ability to remove fitting rules, which comes handy when working with transitions in ConstraintLayout.
  • Demo app with edge-to-edge examples (any kind of contribution is welcome).

Similar libraries

License

Copyright 2020 Sergej Shafarenka, www.halfbit.de

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.