|
69 | 69 | import androidx.core.app.NotificationManagerCompat; |
70 | 70 | import androidx.core.content.ContextCompat; |
71 | 71 | import androidx.core.content.FileProvider; |
| 72 | +import androidx.core.graphics.Insets; |
| 73 | +import androidx.core.view.ViewCompat; |
| 74 | +import androidx.core.view.WindowInsetsCompat; |
72 | 75 | import androidx.drawerlayout.widget.DrawerLayout; |
73 | 76 | import androidx.fragment.app.Fragment; |
74 | 77 | import androidx.fragment.app.FragmentTransaction; |
@@ -697,10 +700,8 @@ public void setUpToolbar(){ |
697 | 700 | getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, this); |
698 | 701 | getSupportActionBar().setSelectedNavigationItem(getUserSelectedNavigationItem()); |
699 | 702 |
|
700 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
701 | | - Window window = getWindow(); |
702 | | - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
703 | | - } |
| 703 | + Window window = getWindow(); |
| 704 | + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
704 | 705 | } |
705 | 706 | catch(Exception ex){ |
706 | 707 | //http://stackoverflow.com/questions/26657348/appcompat-v7-v21-0-0-causing-crash-on-samsung-devices-with-android-v4-2-2 |
@@ -1088,6 +1089,25 @@ public void setupEvenlyDistributedToolbar(){ |
1088 | 1089 | // Toolbar |
1089 | 1090 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom); |
1090 | 1091 |
|
| 1092 | + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.content_layout), (v, windowInsets) -> { |
| 1093 | + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()); |
| 1094 | + |
| 1095 | + // Apply the insets as a margin to the view so it doesn't overlap with status bar |
| 1096 | + ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); |
| 1097 | + mlp.leftMargin = insets.left; |
| 1098 | + mlp.bottomMargin = insets.bottom; |
| 1099 | + mlp.rightMargin = insets.right; |
| 1100 | + // mlp.topMargin = insets.top; |
| 1101 | + v.setLayoutParams(mlp); |
| 1102 | + |
| 1103 | + // Alternatively set the padding on the view itself. |
| 1104 | + // v.setPadding(0, 0, 0, 0); |
| 1105 | + |
| 1106 | + // Return CONSUMED if you don't want want the window insets to keep passing down to descendant views. |
| 1107 | + // return windowInsets; |
| 1108 | + return WindowInsetsCompat.CONSUMED; |
| 1109 | + }); |
| 1110 | + |
1091 | 1111 | // Add 10 spacing on either side of the toolbar |
1092 | 1112 | toolbar.setContentInsetsAbsolute(10, 10); |
1093 | 1113 |
|
|
0 commit comments