Skip to content

Commit 5079ff9

Browse files
authored
Apply insets to decorView (#1335)
1 parent 09ed6bf commit 5079ff9

File tree

1 file changed

+14
-8
lines changed
  • src/main/resources/native/android/android_project/app/src/main/java/com/gluonhq/helloandroid

1 file changed

+14
-8
lines changed

src/main/resources/native/android/android_project/app/src/main/java/com/gluonhq/helloandroid/MainActivity.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.content.Intent;
3333
import android.graphics.PixelFormat;
3434
import android.graphics.Rect;
35+
import android.os.Build;
3536
import android.os.Bundle;
3637
import android.os.Handler;
3738
import android.os.SystemClock;
@@ -41,20 +42,20 @@
4142
import android.util.DisplayMetrics;
4243
import android.util.Log;
4344

44-
import android.view.inputmethod.InputConnection;
45-
4645
import android.view.KeyEvent;
4746
import android.view.KeyCharacterMap;
4847
import android.view.MotionEvent;
4948
import android.view.Surface;
5049
import android.view.SurfaceHolder;
5150
import android.view.SurfaceView;
51+
import android.view.View;
5252
import android.view.ViewConfiguration;
5353
import android.view.ViewGroup;
5454
import android.view.Window;
5555
import android.view.WindowManager;
5656
import android.view.inputmethod.BaseInputConnection;
5757
import android.view.inputmethod.EditorInfo;
58+
import android.view.inputmethod.InputConnection;
5859
import android.view.inputmethod.InputMethodManager;
5960
import android.widget.FrameLayout;
6061

@@ -100,12 +101,17 @@ protected void onCreate(Bundle savedInstanceState) {
100101
setContentView(mViewGroup);
101102
instance = this;
102103

103-
// Apply edge-to-edge display
104-
ViewCompat.setOnApplyWindowInsetsListener(mView, (v, insets) -> {
105-
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
106-
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
107-
return insets;
108-
});
104+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { // > 34
105+
// Prevent edge-to-edge display, keeping the view outside the systemBars
106+
// Warning: this doesn't set the color of the SystemBars, which can be done
107+
// by the StatusBarService in Attach
108+
View decorView = getWindow().getDecorView();
109+
ViewCompat.setOnApplyWindowInsetsListener(decorView, (v, insets) -> {
110+
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
111+
decorView.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
112+
return insets;
113+
});
114+
}
109115

110116
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
111117
Log.v(TAG, "onCreate done");

0 commit comments

Comments
 (0)