javaandroidkotlinedge-to-edge

Edge-to-Edge in Android Libraries


I have a video player library and currently is experiencing issues with the enforced Edge-to-Edge. Video controls and other views go behind the navigation bar and app bar.

I want to solve this issue without including androidx transitive dependency.

The idea is to set the padding of the Activity's content view according to the insets when the Edge-to-Edge is enforced and take no action else.

Thats the solution I designed and want to know if handles everything or can present issues in some cases:

public static void setEdgeToEdgeInsets(View view) {
    Context viewContext = view.getContext();
    if(viewContext instanceof Activity){
        int targetSdk = viewContext.getApplicationInfo().targetSdkVersion;
        if (Build.VERSION.SDK_INT >= 35 && targetSdk>=35) {
            ((Activity)viewContext).getWindow().getDecorView().setOnApplyWindowInsetsListener((v, windowInsets) -> {
                Insets in = windowInsets.getInsets(WindowInsets.Type.systemBars());
                view.setPadding(in.left, in.top, in.right, in.bottom);
                return windowInsets;
            });
        }
    }
}

Solution

  • Other than Cutouts, there should be no other issues.

    But the details you provided are limited; let me break it down to you. The purpose of this new policy is EXACTLY showing some parts of your app that the user isn't interacting with yet. It's some UI/UX stuff.

    If you are trying to have a view as part of (for example) a RecyclerView, then you should consider having a blank part as high as the bottom inset.

    If you are trying to have like full-screen player, try ImmersiveMode