"FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS" 影响 getRootView().getHeight()
"FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS" affects getRootView().getHeight()
我在尝试向状态栏添加颜色时发现了影响相对布局高度的问题。
adding Flag 影响计算相对布局 rootView 的高度。
private void changeStatusBarColor(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.red_e31837));
}
}
我有一个视图树观察器可以帮助我跟踪 rootView 的高度。
private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = wrapper.getRootView().getHeight() - wrapper.getHeight();
}
如果我使用 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
int heightDiff
等于 1920,但如果我不使用 changeStatusBarColor()
,int heightDiff
等于 1776(我猜是在没有操作栏和状态栏的情况下计算的)。
但是为什么添加这个标志改变计算呢?
提前致谢!
在我的例子中,问题出现在 SlidingMenu 库中。这里有一个solution.
我在尝试向状态栏添加颜色时发现了影响相对布局高度的问题。
adding Flag 影响计算相对布局 rootView 的高度。
private void changeStatusBarColor(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.red_e31837));
}
}
我有一个视图树观察器可以帮助我跟踪 rootView 的高度。
private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = wrapper.getRootView().getHeight() - wrapper.getHeight();
}
如果我使用 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
int heightDiff
等于 1920,但如果我不使用 changeStatusBarColor()
,int heightDiff
等于 1776(我猜是在没有操作栏和状态栏的情况下计算的)。
但是为什么添加这个标志改变计算呢?
提前致谢!
在我的例子中,问题出现在 SlidingMenu 库中。这里有一个solution.