最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Edge-to-Edge in Android Libraries - Stack Overflow

programmeradmin9浏览0评论

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;
            });
        }
    }
}

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;
            });
        }
    }
}
Share Improve this question asked Feb 4 at 23:40 AddevAddev 32.2k54 gold badges189 silver badges305 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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

发布评论

评论列表(0)

  1. 暂无评论