7

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;
    }
portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136

0 Answers0