Skip to content

Instantly share code, notes, and snippets.

@iamchiwon
Created July 19, 2019 06:32
Show Gist options
  • Select an option

  • Save iamchiwon/6ec65b26a6e7d86a40ed5aabe1e5bced to your computer and use it in GitHub Desktop.

Select an option

Save iamchiwon/6ec65b26a6e7d86a40ed5aabe1e5bced to your computer and use it in GitHub Desktop.
[Android] statusHeight 얻기
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