Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
1.1 kB
1
Indexable
Never
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Disable decor fitting system windows
    WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

    // Handle window insets
    ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView(), new androidx.core.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            Insets systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemInsets.left, systemInsets.top, systemInsets.right, systemInsets.bottom);
            return insets;
        }
    });

    // Manage insets for navigation and status bars
    WindowInsetsControllerCompat insetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
    if (insetsController != null) {
        insetsController.hide(WindowInsetsCompat.Type.statusBars());
        insetsController.show(WindowInsetsCompat.Type.navigationBars());
    }
}
Leave a Comment