X Tutup
Skip to content

Android: Add method to set root window color at runtime#109491

Merged
Repiteo merged 2 commits intogodotengine:masterfrom
syntaxerror247:window-color
Sep 26, 2025
Merged

Android: Add method to set root window color at runtime#109491
Repiteo merged 2 commits intogodotengine:masterfrom
syntaxerror247:window-color

Conversation

@syntaxerror247
Copy link
Member

@syntaxerror247 syntaxerror247 commented Aug 10, 2025

  • This PR adds a method to set the root window background color at runtime.
  • The second commit uses this method to make the Android editor’s root window color match the editor background color.

What I mean by "root window" here?

The root window is the one on which the Godot app is rendered. It’s only visible in areas where Godot doesn’t render, the status bar, navigation bar, and display cutouts.

#108557 added an export option to set this background color at export time. However, there are valid reasons to want to change it at runtime. For example, I want to change it dynamically based on the app’s theme color.

Currently, it’s already possible to change this color at runtime using JavaClassWrapper and AndroidRuntime. Since I was already adding a method to change it for the Editor, I figured it made sense to expose it as well. That’s the only reason.

Example to set it via JavaClassWrapper
func set_system_bar_color(color: Color, override_appearance := false) -> void:
	if not android_runtime:
		return
	
	var activity = android_runtime.getActivity()
	var callable = func ():
		var window = activity.getWindow()
		var decorView = window.getDecorView()
		decorView.setBackgroundColor(color.to_argb32())
		
		if (is_light_system_bars != (color.get_luminance() > 0.45)) or override_appearance:
			is_light_system_bars = color.get_luminance() > 0.45
			var WindowInsetsControllerCompat = JavaClassWrapper.wrap("androidx.core.view.WindowInsetsControllerCompat")
			var controller = WindowInsetsControllerCompat.call("<init>", window, window.getDecorView())
			controller.setAppearanceLightNavigationBars(is_light_system_bars)
			controller.setAppearanceLightStatusBars(is_light_system_bars)
	
	activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))

Update: It's not trivial to do this via JavaClassWrapper. See #109667

@llama-nl
Copy link

No context?

@syntaxerror247
Copy link
Member Author

No context?

Updated PR description.

@syntaxerror247 syntaxerror247 modified the milestones: 4.x, 4.6 Sep 6, 2025
@syntaxerror247 syntaxerror247 added cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release and removed discussion labels Sep 16, 2025
@clayjohn clayjohn removed the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Sep 26, 2025
@Repiteo Repiteo merged commit 9283328 into godotengine:master Sep 26, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 26, 2025

Thanks!

@syntaxerror247 syntaxerror247 deleted the window-color branch September 27, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

X Tutup