How to get size of NavigationBar and StatusBar

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

How to get size of NavigationBar and StatusBar

How to get size of NavigationBar and StatusBar for Android

magiepooh

July 22, 2016

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

21 slides
  1. Reflection <!-- Height of the status bar --> <dimen name="status_bar_height">24dp</dimen>

    <!-- Height of the bottom navigation / system bar. --> <dimen name=“navigation_bar_height">48dp</dimen> <!-- Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height --> <dimen name=“navigation_bar_height_landscape">48dp</dimen> <!-- Width of the navigation bar when it is placed vertically on the screen --> <dimen name="navigation_bar_width">42dp</dimen>
  2. StatusBar Height public int getStatusBarHeight() { Point smallSize = new

    Point(); Point largeSize = new Point(); display.getCurrentSizeRange(smallSize, largeSize); // getDisplaySize() = getSize() Point displaySize = getDisplaySize(); if (displaySize.x > displaySize.y) { return displaySize.y - smallSize.y; } else { return displaySize.y - largeSize.y; } }
  3. private class ApplyInsetsListener implements android.support.v4.view.OnApplyWindowInsetsListener { @Override public WindowInsetsCompat onApplyWindowInsets(View

    v, WindowInsetsCompat insets) { if (mLastInsets != insets) { mLastInsets = insets; } return insets; } }
  4. public int getNavigationBarWidth() { return mLastInsets == null ? 0

    : mLastInsets.getSystemWindowInsetRight(); } public int getNavigationBarHeight() { return mLastInsets == null ? 0 : mLastInsets.getSystemWindowInsetBottom(); } public int getStatusBarHeight() { return mLastInsets == null ? 0 : mLastInsets.getSystemWindowInsetTop(); }

More Decks by magiepooh

Other Decks in Technology