Is it possible to get the height of soft(virtual) navigation layout? If yes, How to get the height programmatic ally?
Asked
Active
Viewed 106 times
2 Answers
1
This should work:
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;

RobinF
- 349
- 1
- 2
- 17
-
Thank u for response.Its not work.It return 0 even the device has soft navigation layout. – Nas Sep 18 '14 at 17:16
0
DisplayMetrics metrics = new DisplayMetrics();
To get screen metrics wiithout soft navigation layout
getActivity().getWindowManager().getDefaultDisplay()
.getMetrics(metrics);
int usableHeight = metrics.heightPixels;
To get screen metrics with soft navigation layout
getActivity().getWindowManager().getDefaultDisplay()
.getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
When you subtract the usableHeight from the realHeight, you get the actual height of the soft navigation layout.
Note: getRealMetrics() method will work only if the Api level is greater or equal to 17 otherwise it won't work. So check the build version before getting display metrics

Nas
- 2,158
- 1
- 21
- 38