I want to show a view above the navigation bar if it is present on device screen, else if not then at the bottom of the screen.
Asked
Active
Viewed 992 times
0
-
Please donot make question poor, make it proper explained – Jhaman Das Apr 19 '16 at 05:50
-
3While the question should be reworded, other answers only give a workarround by making calcs with the screen height, there should be a cleaner solution. http://stackoverflow.com/questions/28406506/check-if-android-device-has-software-or-hardware-navigation-buttons – Nanoc Apr 19 '16 at 05:54
2 Answers
2
Use this method in your activity or fragment to know whether device has soft navigation bar or not. Then you can do code as per requirement in the method call.
Like this :-
if (hasNavBar(getResources()))
{
//do your code here
}
public boolean hasNavBar (Resources resources)
{
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
return id > 0 && resources.getBoolean(id);
}

Bajirao Shinde
- 1,356
- 1
- 18
- 26

JayJoshi
- 81
- 1
- 1
- 9
0
You can try the following method. It can work perfectly:
public boolean hasNavBar (Resources resources) {
boolean hasNavigationBar = true;
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = resources.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return hasNavigationBar;
}

Zhong W
- 933
- 5
- 5