Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小米手机ImmersionBar.hasNavigationBar(context)判断有误 #567

Open
weijia1991 opened this issue Apr 25, 2023 · 2 comments
Open

小米手机ImmersionBar.hasNavigationBar(context)判断有误 #567

weijia1991 opened this issue Apr 25, 2023 · 2 comments

Comments

@weijia1991
Copy link

Remi Note 5
MIUI 12.0.3
Android 9.0

在无导航栏的情况下,ImmersionBar.hasNavigationBar(context)返回true

@YUHAN-GUO
Copy link

有什么解决方法么?

@weijia1991
Copy link
Author

weijia1991 commented Oct 12, 2024

有什么解决方法么?

时间有点久了,我当时写的代码找不到了。当时用WindowInsets解决的这个问题,去网络搜索了下整理出了下面的代码,代码未经测试仅供参考

public boolean hasNavigationBar(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    //android 5.0以下ViewCompat.getRootWindowInsets会反馈null
    WindowInsetsCompat windowInsets = ViewCompat.getRootWindowInsets(decorView);

    if (null != windowInsets) {
        int top = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).top;
        int bottom = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
        int height = Math.abs(bottom - top);
        return height > 0;
    }
    return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants