Untitled
unknown
plain_text
a year ago
2.1 kB
6
Indexable
import android.app.ActivityManager; import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class YourActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View view = findViewById(R.id.your_view_id); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { ViewCompat.setOnApplyWindowInsetsListener(view, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { WindowInsetsCompat.DisplayCutoutCompat cutout = insets.getDisplayCutout(); if (cutout != null) { int left = cutout.getSafeInsetLeft(); int top = cutout.getSafeInsetTop(); int right = cutout.getSafeInsetRight(); int bottom = cutout.getSafeInsetBottom(); // Check if in split-screen mode ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); boolean isInMultiWindowMode = activityManager.isInMultiWindowMode(); if (isInMultiWindowMode) { // Handle padding for split-screen mode v.setPadding(left, top, right, bottom); } else { // Handle padding for full-screen mode v.setPadding(left, top, right, bottom); } } return insets; } }); } } }
Editor is loading...
Leave a Comment