Example usage for android.view View setFitsSystemWindows

List of usage examples for android.view View setFitsSystemWindows

Introduction

In this page you can find the example usage for android.view View setFitsSystemWindows.

Prototype

public void setFitsSystemWindows(boolean fitSystemWindows) 

Source Link

Document

Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of #fitSystemWindows(Rect) will be executed.

Usage

From source file:fr.outadev.skinswitch.DetailActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
private void applySystemWindowsBottomInset() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        View containerView = findViewById(R.id.container);
        containerView.setFitsSystemWindows(true);

        containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override// w  ww  . ja va2s. c om
            public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                DisplayMetrics metrics = getResources().getDisplayMetrics();

                if (metrics.widthPixels < metrics.heightPixels) {
                    view.setPadding(0, 0, 0, windowInsets.getSystemWindowInsetBottom());
                } else {
                    view.setPadding(0, 0, windowInsets.getSystemWindowInsetRight(), 0);
                }

                return windowInsets.consumeSystemWindowInsets();
            }

        });
    }
}