Skip to content

Commit f2b5316

Browse files
committed
Fix navigation bar and notification bar invisible in newer Androids
Also fixes TextEditorActivity menu bar overlap with notification bar on newer Androids.
1 parent 9d4ffcc commit f2b5316

1 file changed

Lines changed: 63 additions & 6 deletions

File tree

app/src/main/java/com/amaze/filemanager/ui/activities/superclasses/ThemedActivity.java

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
package com.amaze.filemanager.ui.activities.superclasses;
2222

2323
import static android.os.Build.VERSION.SDK_INT;
24+
import static android.os.Build.VERSION_CODES.KITKAT;
25+
import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
2426
import static android.os.Build.VERSION_CODES.LOLLIPOP;
27+
import static android.os.Build.VERSION_CODES.M;
28+
import static android.os.Build.VERSION_CODES.O;
2529
import static com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants.PREFERENCE_COLORED_NAVIGATION;
2630

2731
import com.amaze.filemanager.R;
@@ -58,6 +62,11 @@
5862
import androidx.annotation.Nullable;
5963
import androidx.appcompat.widget.Toolbar;
6064
import androidx.core.content.ContextCompat;
65+
import androidx.core.graphics.Insets;
66+
import androidx.core.view.ViewCompat;
67+
import androidx.core.view.WindowCompat;
68+
import androidx.core.view.WindowInsetsCompat;
69+
import androidx.core.view.WindowInsetsControllerCompat;
6170
import androidx.preference.PreferenceManager;
6271

6372
/** Created by arpitkh996 on 03-03-2016. */
@@ -86,6 +95,38 @@ public void onReceive(Context context, Intent i) {
8695
}
8796
};
8897

98+
@Override
99+
public void setContentView(int layoutResID) {
100+
super.setContentView(layoutResID);
101+
setupEdgeToEdgeInsets();
102+
}
103+
104+
@Override
105+
public void setContentView(View view) {
106+
super.setContentView(view);
107+
setupEdgeToEdgeInsets();
108+
}
109+
110+
/**
111+
* Apply system bar insets as padding on the content view to handle Android 15+ edge-to-edge
112+
* enforcement. This ensures content is laid out below the status bar and above the navigation
113+
* bar.
114+
*/
115+
private void setupEdgeToEdgeInsets() {
116+
if (SDK_INT >= 35) {
117+
View contentView = findViewById(android.R.id.content);
118+
if (contentView != null) {
119+
ViewCompat.setOnApplyWindowInsetsListener(
120+
contentView,
121+
(v, windowInsets) -> {
122+
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
123+
v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
124+
return WindowInsetsCompat.CONSUMED;
125+
});
126+
}
127+
}
128+
}
129+
89130
@Override
90131
public void onCreate(Bundle savedInstanceState) {
91132
super.onCreate(savedInstanceState);
@@ -108,7 +149,7 @@ public void onCreate(Bundle savedInstanceState) {
108149
getColorPreference().saveColorPreferences(getPrefs(), ColorPreferenceHelper.randomize(this));
109150
}
110151

111-
if (SDK_INT >= 21) {
152+
if (SDK_INT >= LOLLIPOP) {
112153
ActivityManager.TaskDescription taskDescription =
113154
new ActivityManager.TaskDescription(
114155
getString(R.string.appbar_name),
@@ -132,8 +173,13 @@ public void initStatusBarResources(View parentView) {
132173
}
133174

134175
Window window = getWindow();
135-
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
136-
if (findViewById(R.id.tab_frame) != null || findViewById(R.id.drawer_layout) == null) {
176+
if (SDK_INT >= LOLLIPOP) {
177+
boolean useSolidStatusBar =
178+
findViewById(R.id.tab_frame) != null
179+
|| findViewById(R.id.drawer_layout) == null
180+
|| getAppTheme().equals(AppTheme.LIGHT);
181+
182+
if (useSolidStatusBar) {
137183
window.setStatusBarColor(PreferenceUtils.getStatusColor(getPrimary()));
138184
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
139185
} else {
@@ -150,8 +196,19 @@ public void initStatusBarResources(View parentView) {
150196
window.setNavigationBarColor(Utils.getColor(this, R.color.holo_dark_background));
151197
}
152198
}
153-
} else if (SDK_INT == Build.VERSION_CODES.KITKAT_WATCH
154-
|| SDK_INT == Build.VERSION_CODES.KITKAT) {
199+
200+
// Set light/dark icon appearance for system bars based on theme
201+
if (SDK_INT >= M) {
202+
WindowInsetsControllerCompat insetsController =
203+
WindowCompat.getInsetsController(window, window.getDecorView());
204+
boolean isLightTheme = getAppTheme().equals(AppTheme.LIGHT);
205+
insetsController.setAppearanceLightStatusBars(isLightTheme);
206+
if (SDK_INT >= O) {
207+
insetsController.setAppearanceLightNavigationBars(isLightTheme);
208+
}
209+
}
210+
} else if (SDK_INT == KITKAT_WATCH
211+
|| SDK_INT == KITKAT) {
155212
setKitkatStatusBarMargin(parentView);
156213
setKitkatStatusBarTint();
157214
}
@@ -212,7 +269,7 @@ private Toolbar getToolbar() {
212269

213270
void setTheme() {
214271
AppTheme theme = getAppTheme();
215-
if (Build.VERSION.SDK_INT >= 21) {
272+
if (SDK_INT >= LOLLIPOP) {
216273

217274
String stringRepresentation = String.format("#%06X", (0xFFFFFF & getAccent()));
218275

0 commit comments

Comments
 (0)