1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Android: Add method to set root window color at runtime

This commit is contained in:
Anish Mishra
2025-08-10 19:57:02 +05:30
parent a3b42d85d2
commit 0ad232423d
8 changed files with 50 additions and 10 deletions

View File

@@ -260,16 +260,7 @@ class Godot private constructor(val context: Context) {
useImmersive.set(true)
newArgs.add(commandLine[i])
} else if (commandLine[i] == "--background_color") {
val colorStr = commandLine[i + 1]
try {
backgroundColor = colorStr.toColorInt()
Log.d(TAG, "background color = $backgroundColor")
} catch (e: java.lang.IllegalArgumentException) {
Log.d(TAG, "Failed to parse background color: $colorStr")
}
runOnHostThread {
getActivity()?.window?.decorView?.setBackgroundColor(backgroundColor)
}
setWindowColor(commandLine[i + 1])
} else if (commandLine[i] == "--use_apk_expansion") {
useApkExpansion = true
} else if (hasExtra && commandLine[i] == "--apk_expansion_md5") {
@@ -492,6 +483,21 @@ class Godot private constructor(val context: Context) {
}
}
fun setWindowColor(colorStr: String) {
val color = try {
colorStr.toColorInt()
} catch (e: java.lang.IllegalArgumentException) {
Log.w(TAG, "Failed to parse background color: $colorStr", e)
return
}
val decorView = getActivity()?.window?.decorView ?: return
runOnHostThread {
decorView.setBackgroundColor(color)
backgroundColor = color
setSystemBarsAppearance()
}
}
/**
* Used to complete initialization of the view used by the engine for rendering.
*