How to know when Samsung S8, S8+, S9, ect bottom navigation bar is visible?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 04:45:12

问题


The bottom navigation bar on Samsung S8, S8+, S9, ect causes a UI and animation nightmare for views moving in and out from top and bottom of my app when toggled off. For these devices if the navigation bar is toggle on everything works perfectly, but if toggled off the animations all fall short by approximately the height of the navigation bar. My idea is to adjust the animations, however, I am having a difficult time figuring out when a phone has a bottom navigation bar and it is toggled off.

I created a helper method that does a pretty good job of letting me know that a device has a navigation bar toggled on. This function will return true for all devices that have a navigation bar and it is turned on. But the case I want to handle is when it is toggled off. Problem is, toggled off is just like all other phones. How to resolve this? Is there a way to force the navigation bar to display permanently and always?

   public static boolean hasNavBar(@NonNull Activity activity, @NonNull View rootView) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return true;
        }

        // retrieve the window manager for showing custom windows
        Display d = activity.getWindowManager().getDefaultDisplay();
        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int viewHeight = rootView.getHeight();
        if (viewHeight == 0) {
            return true;
        }
        int realHeight = realDisplayMetrics.heightPixels;
        return realHeight != viewHeight;
    }

来源:https://stackoverflow.com/questions/51317263/how-to-know-when-samsung-s8-s8-s9-ect-bottom-navigation-bar-is-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!