I just re-read that too. Devices before API 29 probably do not have a notch/cutout, and the use of the latest API in the extension excludes Android 10 devices, but other methods are available.
Which library or API are you using?
Because I didn't notice that you were using it, I think it was specific to Android, right?
I forget exactly, but guess it is probably the windowInsetscontroller
Well... as I told you, here is the preview and stable version
Tested from Android 10 to Android 15, I don't have any friends with lower versions of Android (but it should work fine)
I think not allowing the navbar to be colored when the StatusBar is hidden is an Android policy (since 10 or 11, I couldn't find a solution; if I removed the edge-to-edge feature, it left a black patch)
Hidebars MOD [TIMAI2] v2.txt (10.4 KB)
I apologize if you see some things in Spanish (I'm too lazy to translate it, jajaja)
Now, the goal is to create a fake bar in Android 15 to be able to add color to the background
Post a test aia.
Thank you for your efforts so far
What happens when you click on the second button (Light/Dark mode, Click / LongClick)?
I tested my app (APK) now on Android 9 (Samsung, Xiaomi), 10, 11 (Pixel 2XL), 13 (Samsung, OnePlus 8), 16 (Pixel Pro 7).
No issues at all.
It's only in the status bar hide, the rest works fine.
(I'm attaching a video)
It's really strange jajaja, but on Android 15 there are no glitches (at least on Samsung devices).
Ok, I'll check it again.
In Android 15, I haven't solved the problem of painting the bar with a solid color. Yesterday, I came up with the idea of making a fake bar with an array, since it's the only possible solution, but it would mean touching the XML files, which would be more work :v
The other option is to paint the background with an array behind it, similar to what I understood from TIM's project.
I cheched it again on all devices. No problems, except on the OnePlus 8. I suspect it's because of the very wide notch, which would otherwise cover relevant parts of the app.
I have almost 20 test devices (Android 4.3, 5.x, 6, 7.x, 8.x, 9, 10, 11, 12, 13, 16. Maybe I'll check it later on other devices with Android 5+.
Maybe, tonight I'll try it on other phones belonging to my family and let you know.
We seem to have drifted...
This topic is about setting Status and Nav Bar colours for Android 15+, you both seem to be focusing on this requirement for android versions < 10.
I have not seen any code that allows us to set the colour of the status bar and the nav bar independently, with different colours, which is what was possible before API35 / Android 15 devices.
I have code that will set both bars to the same colour.
@SimpleFunction(description = "sets system bars colours")
public void SetSystemBarsColours(int colour) {
Window scrn = this.activity.getWindow();
if (Build.VERSION.SDK_INT >= 35) {
WindowInsets windowInsets = scrn.getDecorView().getRootWindowInsets();
scrn.getDecorView().setOnApplyWindowInsetsListener((view, insets) -> {
int StatusHeight = windowInsets.getInsets(WindowInsets.Type.systemBars()).top;
view.setPadding(0, StatusHeight, 0, 0);
view.setBackgroundColor(colour);
return insets;
});
} else {
scrn.setStatusBarColor(colour);
scrn.setNavigationBarColor(colour);
}
}
This code (from here), seems to indicate the ability to set different colours to the status and nav bars, but it is written in Kotlin:1. Don't know how to convert this to Java,2. Don't know if it will work in an AI2 extension.
fun setStatusBarColor(ctx: Context, activity: AppCompatActivity, rootLayout: View, window: Window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { // Android 15+
//Below code is for giving the background color to Navigation Bar
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
view.setBackgroundColor(Color.BLACK)
insets
}
ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val height = insets.top
//Below code is for adding padding top and bottom
v.updateLayoutParams<MarginLayoutParams> {
topMargin = insets.top
bottomMargin = insets.bottom
}
val statusBarView = View(ctx)
//Below code is for settings color and height to notification bar
statusBarView.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
height
)
statusBarView.setBackgroundColor(ContextCompat.getColor(ctx, R.color.colorPrimary))
activity.addContentView(statusBarView, statusBarView.layoutParams)
WindowInsetsCompat.CONSUMED
}
} else {
// For Android 14 and below
window.statusBarColor = ContextCompat.getColor(ctx, R.color.colorPrimary)
}
}
I asked Gemini for you
Taifun
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.ViewGroup.MarginLayoutParams;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.updateLayoutParams;
public class UiUtils {
public static void setStatusBarColor(Context ctx, AppCompatActivity activity, View rootLayout, Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { // Renamed from VANILLA_ICE_CREAM
// Below code is for giving the background color to the Navigation Bar
window.getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
view.setBackgroundColor(Color.BLACK);
return insets;
}
});
ViewCompat.setOnApplyWindowInsetsListener(rootLayout, (v, windowInsets) -> {
WindowInsetsCompat.getInsets(windowInsets, WindowInsetsCompat.Type.systemBars());
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
int height = insets.top;
// Below code is for adding padding top and bottom
v.updateLayoutParams(params -> {
if (params instanceof MarginLayoutParams) {
MarginLayoutParams marginParams = (MarginLayoutParams) params;
marginParams.topMargin = insets.top;
marginParams.bottomMargin = insets.bottom;
}
});
View statusBarView = new View(ctx);
// Below code is for setting color and height to the notification bar
statusBarView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
height
));
statusBarView.setBackgroundColor(ContextCompat.getColor(ctx, R.color.colorPrimary));
activity.addContentView(statusBarView, statusBarView.getLayoutParams());
return WindowInsetsCompat.CONSUMED;
});
} else {
// For Android 14 and below
window.setStatusBarColor(ContextCompat.getColor(ctx, R.color.colorPrimary));
}
}
}