|
27 | 27 | import android.util.TypedValue;
|
28 | 28 | import android.view.MotionEvent;
|
29 | 29 | import android.view.View;
|
| 30 | +import android.view.ViewGroup; |
30 | 31 | import android.view.Window;
|
31 | 32 | import android.widget.ImageView;
|
32 | 33 | import android.widget.TextView;
|
|
38 | 39 | import androidx.appcompat.app.AppCompatActivity;
|
39 | 40 | import androidx.appcompat.app.AppCompatDelegate;
|
40 | 41 | import androidx.core.graphics.ColorUtils;
|
| 42 | +import androidx.core.graphics.Insets; |
41 | 43 | import androidx.core.os.LocaleListCompat;
|
| 44 | +import androidx.core.view.ViewCompat; |
| 45 | +import androidx.core.view.WindowInsetsCompat; |
42 | 46 | import androidx.core.view.WindowInsetsControllerCompat;
|
43 | 47 | import androidx.core.widget.TextViewCompat;
|
44 | 48 | import androidx.exifinterface.media.ExifInterface;
|
@@ -1093,4 +1097,20 @@ public static boolean deviceHasCamera(Context context) {
|
1093 | 1097 | return false;
|
1094 | 1098 | }
|
1095 | 1099 | }
|
| 1100 | + |
| 1101 | + public static void applyWindowInsets(View root) { |
| 1102 | + /* This function basically fakes the activity being edge-to-edge. Useful for those activities that are really hard to get to behave well */ |
| 1103 | + ViewCompat.setOnApplyWindowInsetsListener(root, (view, windowInsets) -> { |
| 1104 | + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); |
| 1105 | + |
| 1106 | + ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); |
| 1107 | + layoutParams.leftMargin = insets.left; |
| 1108 | + layoutParams.bottomMargin = insets.bottom; |
| 1109 | + layoutParams.rightMargin = insets.right; |
| 1110 | + layoutParams.topMargin = insets.top; |
| 1111 | + view.setLayoutParams(layoutParams); |
| 1112 | + |
| 1113 | + return WindowInsetsCompat.CONSUMED; |
| 1114 | + }); |
| 1115 | + } |
1096 | 1116 | }
|
0 commit comments