// 该方法需要在View完全被绘制出来之后调用 @JvmStatic privatefunisNavigationBarVisible(activity: Activity): Boolean { val vp = activity.window.decorView as ViewGroup? if (vp != null) { for (i in0 until vp.childCount) { vp.getChildAt(i).context.packageName if (vp.getChildAt(i).id !== View.NO_ID && NAVIGATION == activity.resources.getResourceEntryName(vp.getChildAt(i).id) ) { returntrue } } } returnfalse }
/** * 获取屏幕的物理大小 px */ @JvmStatic fungetDeviceScreenSize(context: Context): Point { val appContext = context.applicationContext val wm = appContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager val point = Point(0, 0) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { wm.defaultDisplay.getRealSize(point) } else { wm.defaultDisplay.getSize(point) } return point }
/** * 获取显示屏幕的宽高 px */ @JvmStatic fungetDisplaySize(context: Context): Point { val point = Point(0, 0) val dm = context.applicationContext.resources.displayMetrics point.x = dm.widthPixels point.y = dm.heightPixels return point } }