Giter Club home page Giter Club logo

edge-to-edge's Introduction

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>

โ˜๏ธ Note that fully transparent navigation bar can cause contrast issues to the navigation icons for API level [23..29). Check Navigation Bar Transparency wiki page for more details.

  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.

edge-to-edge's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

edge-to-edge's Issues

set Navigationbar color transparent ,but in android Q the navigationbar color is half black

1600966370805

The navigation bar color is transparent, But the navigationBar in Android Q it displays half black.

Then I check the google calendar app, the navigation bar can be half white. can it be we set the navigationBar transparent, the navigation bar goes with the theme color, Or we can set the navigation bar look the normal color half white?

The Google suggests set the color transparent , so if we set another color can use perform the adapter color change which the Android Q help us achieve the function

1600966330072

Issue on Android 29

It appears that the implementation doesn't work properly when I set edge-to-edge on an Activity. The bottom navigation bar is still fully transparent. For example:

device-2020-06-15-073908

What I want is to have the bottom navigation bar semi-transparent:
device-2020-06-15-074115

My fix is to have the Edge-to-Edge use the "android.R.id.content" view as the root view instead of the decor view.

I have created a project that shows the issue and the fix. See https://github.com/thierryd/EdgeToEdgeActivityIssue

Transparent navigation bar causes UI issues on pre-Q devices

Thanks for such a convenient library.

Wanted to report that the way you suggest in the README file works good for screens with no navigation bar, but for devices with good old navigation bar (like we have in Android versions before 9) setting navigation color to transparent causes issues with these navigation bars making navigation buttons almost invisible.

Here is a screenshot taken from your sample app on Android 7:
Screenshot 2020-04-14 at 19 38 02

I guess it should be mentioned in README that such transparent navigation bar should be set only for values-29 as it is mentioned in Google`s doc: https://developer.android.com/training/gestures/gesturenav#transparent-bars

I will open a PR quit later mentioning it if you don't mind.

Edge-to-edge behaviour on Android R

On Android R, the behaviour of ViewCompat.setOnApplyWindowInsetsListener has changed to support IME (see for example https://proandroiddev.com/exploring-windowinsets-on-android-11-a80cf8fe19be).

I currently have a fragment that is used in two different location in my app:

  1. As the main fragment of a single activity
  2. As a fragment inside a CoordinatorLayout in another activity

My app is build like so:

  1. The fragment calls edgeToEdge() to include padding for the top system bar
  2. The CoordinatorLayout also calls edgeToEdge() to include padding for the top system bar

In API 29, the fragment inside the CoordinatorLayout won't get OnApplyWindowInsetsListener called
In API 30, the fragment do get OnApplyWindowInsetsListener called (probably due to the change for the new IME code)

Now, my fix right now is just to check if the fragment is not inside a CoordinatorLayout to call fragment.edgeToEdge().

But I'm wondering if there is anything that could be done in the edge-to-edge library to fix this instead. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.