We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int resourceId = Resources.getSystem().getIdentifier(key, "dimen", "android"); if (resourceId > 0) { int sizeOne = context.getResources().getDimensionPixelSize(resourceId); int sizeTwo = Resources.getSystem().getDimensionPixelSize(resourceId); // android9以上版本,可以通过修改开发者选项里的刘海屏,Resources.getSystem()也会导致获得的状态栏高度不准确, // 可以通过context.getResources()方式来获取准确的高度。 // 假如android9以上手机又使用了今日头条适配方案而且开发者选项里开启了刘海屏,那样两种方式获得density有可能不一样, // 所以通过densityTwo / densityOne来修复正确的高度 if (sizeTwo >= sizeOne && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !key.equals("status_bar_height"))) { result = sizeTwo; } else { float densityOne = context.getResources().getDisplayMetrics().density; float densityTwo = Resources.getSystem().getDisplayMetrics().density; float f = sizeOne * densityTwo / densityOne; result = (int) ((f >= 0) ? (f + 0.5f) : (f - 0.5f)); } }
想问下获取状态栏高度的时候,为啥,sizeTwo>=sizeOne的时候取这个sizeTwo。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
想问下获取状态栏高度的时候,为啥,sizeTwo>=sizeOne的时候取这个sizeTwo。
The text was updated successfully, but these errors were encountered: