Reliably get height of status bar to solve KitKat translucent navigation issue

后端 未结 4 1305
轻奢々
轻奢々 2020-12-14 01:45

I am experimenting with the new Android 4.4 translucent navigation bars and would like to set the navigation bar as translucent using the FLAG_TRANSLUCENT_NAVIGATION

4条回答
  •  温柔的废话
    2020-12-14 01:45

    Since api 21 there is official method for retrieving insets for status bar and navigation bar height when is translucent

    ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
            @Override
            public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                final int statusBar = insets.getSystemWindowInsetTop();
                final int navigationBar = insets.getSystemWindowInsetBottom();
                return insets;
            }
        });
    

提交回复
热议问题