Skip to content

Commit 1c4da2d

Browse files
committed
The GPS Main Activity should now adjust to the insets in edge to edge layouts
Issue #1110
1 parent 30cc6f8 commit 1c4da2d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
import androidx.core.app.NotificationManagerCompat;
7070
import androidx.core.content.ContextCompat;
7171
import androidx.core.content.FileProvider;
72+
import androidx.core.graphics.Insets;
73+
import androidx.core.view.ViewCompat;
74+
import androidx.core.view.WindowInsetsCompat;
7275
import androidx.drawerlayout.widget.DrawerLayout;
7376
import androidx.fragment.app.Fragment;
7477
import androidx.fragment.app.FragmentTransaction;
@@ -697,10 +700,8 @@ public void setUpToolbar(){
697700
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, this);
698701
getSupportActionBar().setSelectedNavigationItem(getUserSelectedNavigationItem());
699702

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);
704705
}
705706
catch(Exception ex){
706707
//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(){
10881089
// Toolbar
10891090
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom);
10901091

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+
10911111
// Add 10 spacing on either side of the toolbar
10921112
toolbar.setContentInsetsAbsolute(10, 10);
10931113

0 commit comments

Comments
 (0)