getLocationOnScreen() will get the location based on the phone screen.
getLocationInWindow() will get the location based on the activity window. 水滴屏獲取位置用這種
|--phone screen--------------------- |
|--------status bar---------------------|
| |
|-------------------------------------------|
|--------activity window------ -------|
| |
| |
| |
| |
| |
| |
|-------------------------------------------|
2.statusBarHeight會隨著有無通知改變
3.是否有劉海屏 水滴屏
/**
* 是否有劉海屏
*
* @return
*/
public static boolean hasNotchInScreen(Activity activity) {
if (activity == null || activity.isFinishing()) return false;
boolean result = false;
// 通過其他方式判斷是否有劉海屏 目前官方提供有開發(fā)文檔的就 小米,vivo擦囊,華為(榮耀)蕴轨,oppo
String manufacturer = Build.MANUFACTURER;
Log.i("cchen", "manufacturer " + manufacturer);
if (TextUtils.isEmpty(manufacturer)) {
return false;
} else if (manufacturer.equalsIgnoreCase("HUAWEI")) {
result = hasNotchHw(activity);
} else if (manufacturer.equalsIgnoreCase("xiaomi")) {
result = hasNotchXiaoMi(activity);
} else if (manufacturer.equalsIgnoreCase("oppo")) {
result = hasNotchOPPO(activity);
} else if (manufacturer.equalsIgnoreCase("vivo")) {
result = hasNotchVIVO(activity);
}
if(result) return true;
// android P 以上有標(biāo)準(zhǔn) API 來判斷是否有劉海屏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
DisplayCutout displayCutout = activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
Log.i("cchen", "displayCutout " + displayCutout);
if (displayCutout != null) {
// 說明有劉海屏
return true;
}
}
return false;
}
/**
* 判斷vivo是否有劉海屏
* https://swsdl.vivo.com.cn/appstore/developer/uploadfile/20180328/20180328152252602.pdf
*
* @param activity
* @return
*/
private static boolean hasNotchVIVO(Activity activity) {
try {
Class<?> c = Class.forName("android.util.FtFeature");
Method get = c.getMethod("isFeatureSupport", int.class);
return (boolean) (get.invoke(c, 0x20));
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 判斷oppo是否有劉海屏
* https://open.oppomobile.com/wiki/doc#id=10159
*
* @param activity
* @return
*/
private static boolean hasNotchOPPO(Activity activity) {
return activity.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
}
/**
* 判斷xiaomi是否有劉海屏
* https://dev.mi.com/console/doc/detail?pId=1293
*
* @param activity
* @return
*/
private static boolean hasNotchXiaoMi(Activity activity) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("getInt", String.class, int.class);
return (int) (get.invoke(c, "ro.miui.notch", 0)) == 1;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 判斷華為是否有劉海屏
* https://devcenter-test.huawei.com/consumer/cn/devservice/doc/50114
*
* @param activity
* @return
*/
private static boolean hasNotchHw(Activity activity) {
try {
ClassLoader cl = activity.getClassLoader();
Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
return (boolean) get.invoke(HwNotchSizeUtil);
} catch (Exception e) {
return false;
}
}
4.Button在約束布局中擋住其他view锡溯,是因為button自帶elevation,在Z軸上高于其他view魏割。
Button和TextView的不同
Button 有背景,點擊,按下都有相應(yīng)的效果眨八。
可點擊。
默認(rèn)有焦點左电。
樣式不同廉侧,比如顏色页响,位置等
5.removeView由于有LayoutTransition而刪除失敗
6.彈出dialog時,window不退出全屏段誊,虛擬鍵不彈出
在show 之前 闰蚕,getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);