gyf-dev / gyf-dev/ImmersionBar

获取状态栏高度

Open
#569 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
11.5k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

 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。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java block shown in the issue and review how Android's Resources.getSystem() and context.getResources() return dimension values. Done means providing a documented explanation of why sizeTwo is preferred when it is at least sizeOne, including any version or display-density conditions involved.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.