/*
* 判断手机是否有底部虚拟按键
* */
public boolean checkDeviceHasNavigationBar(Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.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;
} elseif ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
2,解决popupwindow在7.0以上机型设置居于view下方却盖在了view上面的问题
if (Build.VERSION.SDK_INT < 24) {
popupWindow.showAsDropDown(v);
} else {
int[] location = new int[2];
v.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, 0, y + v.getHeight());
}
======常见问题==================
一,androidstudio编译相关
1, Error while Installing APK
解决方案:重新sync按钮编译下gradle就可以了
2,出现Execution failed for task类的错误
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
TaskExecutionException: Execution failed for task ':app:transformClassesWithAspectTransformForDebug'