Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get an instance of DisplayCutoutCompat

I'm looking for a way to use DisplayCutoutCompat since I want to know the height of the notch of the device to move the layout.

The documentation does not really point out how to get an instance within the onCreate method.

like image 508
rekire Avatar asked Jul 31 '18 05:07

rekire


1 Answers

You can do it using ViewCompat like below

ViewCompat.setOnApplyWindowInsetsListener(yourView, new OnApplyWindowInsetsListener() {
            @Override
            public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat) {
                //This is where you get DisplayCutoutCompat
                windowInsetsCompat.getDisplayCutout();
                return windowInsetsCompat;
            }
        });
like image 182
Annah Avatar answered Nov 05 '22 14:11

Annah