Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to get size of NavigationBar and StatusBar

How to get size of NavigationBar and StatusBar

How to get size of NavigationBar and StatusBar for Android

magiepooh

July 22, 2016
Tweet

More Decks by magiepooh

Other Decks in Technology

Transcript

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