【发布时间】:2017-09-15 11:09:40
【问题描述】:
如果导航栏出现在设备屏幕上,我想在导航栏上方显示一个视图,否则在屏幕底部显示。
【问题讨论】:
-
请不要把问题弄得不好,请适当解释
-
虽然应该改写问题,但其他答案只能通过使用屏幕高度进行计算来解决问题,应该有一个更清洁的解决方案。 stackoverflow.com/questions/28406506/…
标签: android
如果导航栏出现在设备屏幕上,我想在导航栏上方显示一个视图,否则在屏幕底部显示。
【问题讨论】:
标签: android
在您的活动或片段中使用此方法来了解设备是否具有软导航栏。 然后你可以在方法调用中按照要求做代码。
像这样:-
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);
}
【讨论】:
您可以尝试以下方法。它可以完美运行:
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;
}
【讨论】: