Created
July 19, 2019 06:32
-
-
Save iamchiwon/6ec65b26a6e7d86a40ed5aabe1e5bced to your computer and use it in GitHub Desktop.
[Android] statusHeight 얻기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onCreate() { | |
| if (Build.VERSION.SDK_INT >= 21) { | |
| windowInsetsRelay = PublishRelay.create(); | |
| RelativeLayout base = findViewById(R.id.navi_activity_base); | |
| base.requestApplyInsets(); | |
| base.setOnApplyWindowInsetsListener((v, insets) -> { | |
| windowInsetsRelay.accept(insets); | |
| return insets.consumeSystemWindowInsets(); | |
| }); | |
| } | |
| } | |
| onConfigurationChanged() { | |
| if (Build.VERSION.SDK_INT >= 21) { | |
| RelativeLayout base = findViewById(R.id.navi_activity_base); | |
| base.requestApplyInsets(); // 홈화면 나갔다가 다시 돌아올 경우 windowInsets 콜백이 오지 않는 경우가 있어 사용. | |
| if (disposable != null) { | |
| disposable.dispose(); | |
| } | |
| disposable = windowInsetsRelay.debounce(100, TimeUnit.MILLISECONDS) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(insets -> { | |
| naviView.setStatusBarHeights(insets.getSystemWindowInsetTop()); | |
| configurationChanged(); | |
| }); | |
| } else { | |
| configurationChanged(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment