NavigationBar Width
public int getNavigationBarWidth() {
return getRealSize().x - getDisplaySize().x;
}
Slide 20
Slide 20 text
NavigationBar Height
public int getNavigationBarHeight() {
return getRealSize().y - getDisplaySize().y;
}
Slide 21
Slide 21 text
StatusBar Height
public int getStatusBarHeight() {
Point smallSize = new Point();
Point largeSize = new Point();
display.getCurrentSizeRange(smallSize, largeSize);
// getDisplaySize() means getSize()
Point displaySize = getDisplaySize();
if (displaySize.x > displaySize.y) {
return displaySize.y - smallSize.y;
} else {
return displaySize.y - largeSize.y;
}
}
Slide 22
Slide 22 text
3. WindowInsetsCompat
Slide 23
Slide 23 text
private class ApplyInsetsListener implements
android.support.v4.view.OnApplyWindowInsetsListener {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v,
WindowInsetsCompat insets) {
if (mLastInsets != insets) {
mLastInsets = insets;
}
return insets;
}
}
Slide 24
Slide 24 text
ViewCompat.setOnApplyWindowInsetsListener(view,
new ApplyInsetsListener());
Slide 25
Slide 25 text
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();
}