Skip to content

Commit 1e1b4f1

Browse files
light navigation bar
1 parent fd1d911 commit 1e1b4f1

File tree

4 files changed

+79
-58
lines changed

4 files changed

+79
-58
lines changed

plugin/demo/main.gd

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ func _on_color_picker_button_color_changed(color: Color) -> void:
1313
$ColorRect.color = color
1414
$SystemBarColorChanger.set_status_bar_color(color)
1515
$SystemBarColorChanger.set_navigation_bar_color(color)
16+
17+
func _on_light_status_bar_toggled(toggled_on: bool) -> void:
18+
$SystemBarColorChanger.lightStatusBar = toggled_on
19+
20+
21+
func _on_light_navigation_bar_toggled(toggled_on: bool) -> void:
22+
$SystemBarColorChanger.lightNavigationBar = toggled_on

plugin/demo/main.tscn

+63-48
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://cg3hylang5fxn"]
1+
[gd_scene load_steps=6 format=3 uid="uid://cg3hylang5fxn"]
22

33
[ext_resource type="Script" path="res://main.gd" id="1_j0gfq"]
44
[ext_resource type="Script" path="res://addons/SystemBarColorChanger/SystemBarColorChanger.gd" id="2_wvwyx"]
55

66
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jwo12"]
77
bg_color = Color(0.151276, 0.151276, 0.151276, 1)
88

9+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tvfxw"]
10+
content_margin_left = 30.0
11+
content_margin_right = 30.0
12+
bg_color = Color(0.0588235, 0.25098, 0.25098, 1)
13+
14+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_7vx7x"]
15+
content_margin_left = 30.0
16+
content_margin_right = 30.0
17+
bg_color = Color(0.0588235, 0.25098, 0.25098, 1)
18+
919
[node name="Main" type="Control"]
1020
layout_mode = 3
1121
anchors_preset = 15
@@ -22,71 +32,76 @@ anchor_right = 1.0
2232
anchor_bottom = 1.0
2333
grow_horizontal = 2
2434
grow_vertical = 2
25-
color = Color(0, 0.827718, 0.828103, 1)
26-
27-
[node name="Button" type="Button" parent="."]
28-
layout_mode = 1
29-
anchors_preset = 8
30-
anchor_left = 0.5
31-
anchor_top = 0.5
32-
anchor_right = 0.5
33-
anchor_bottom = 0.5
34-
offset_left = -140.0
35-
offset_top = -122.0
36-
offset_right = 140.0
37-
offset_bottom = -60.0
38-
grow_horizontal = 2
39-
grow_vertical = 2
40-
text = "Change Status Bar Color"
41-
42-
[node name="Button2" type="Button" parent="."]
43-
layout_mode = 1
44-
anchors_preset = 8
45-
anchor_left = 0.5
46-
anchor_top = 0.5
47-
anchor_right = 0.5
48-
anchor_bottom = 0.5
49-
offset_left = -140.0
50-
offset_top = 21.0
51-
offset_right = 140.0
52-
offset_bottom = 83.0
53-
grow_horizontal = 2
54-
grow_vertical = 2
55-
text = "Change Navigation Bar Color"
35+
color = Color(0, 0.473914, 0.474144, 1)
5636

5737
[node name="SystemBarColorChanger" type="Node" parent="."]
5838
script = ExtResource("2_wvwyx")
5939

60-
[node name="ColorPickerButton" type="ColorPickerButton" parent="."]
40+
[node name="VBoxContainer" type="VBoxContainer" parent="."]
6141
layout_mode = 1
62-
anchors_preset = 5
63-
anchor_left = 0.5
64-
anchor_right = 0.5
65-
offset_left = -122.5
66-
offset_top = 92.0
67-
offset_right = 122.5
68-
offset_bottom = 161.0
42+
anchors_preset = 15
43+
anchor_right = 1.0
44+
anchor_bottom = 1.0
45+
offset_left = 48.0
46+
offset_top = 71.0
47+
offset_right = -62.0
48+
offset_bottom = -76.0
6949
grow_horizontal = 2
50+
grow_vertical = 2
51+
theme_override_constants/separation = 30
52+
53+
[node name="ColorPickerButton" type="ColorPickerButton" parent="VBoxContainer"]
54+
custom_minimum_size = Vector2(0, 60)
55+
layout_mode = 2
7056
color = Color(0.594336, 0.58547, 0.868764, 1)
7157

72-
[node name="Label" type="Label" parent="ColorPickerButton"]
58+
[node name="Label" type="Label" parent="VBoxContainer/ColorPickerButton"]
7359
layout_mode = 1
7460
anchors_preset = 7
7561
anchor_left = 0.5
7662
anchor_top = 1.0
7763
anchor_right = 0.5
7864
anchor_bottom = 1.0
79-
offset_left = -183.5
80-
offset_top = 15.0
81-
offset_right = 205.5
82-
offset_bottom = 51.0
65+
offset_left = -199.5
66+
offset_top = 4.0
67+
offset_right = 199.5
68+
offset_bottom = 27.0
8369
grow_horizontal = 2
8470
grow_vertical = 0
8571
theme_override_styles/normal = SubResource("StyleBoxFlat_jwo12")
8672
text = "Click On this ☝️ button to change color dynamically"
8773
horizontal_alignment = 1
8874
vertical_alignment = 1
8975

90-
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
91-
[connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"]
92-
[connection signal="color_changed" from="ColorPickerButton" to="." method="_on_color_picker_button_color_changed"]
76+
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
77+
layout_mode = 2
78+
79+
[node name="light_status_bar" type="CheckButton" parent="VBoxContainer"]
80+
custom_minimum_size = Vector2(0, 60)
81+
layout_mode = 2
82+
theme_override_styles/pressed = SubResource("StyleBoxFlat_tvfxw")
83+
theme_override_styles/normal = SubResource("StyleBoxFlat_7vx7x")
84+
text = "LIght Status Bar"
85+
86+
[node name="light_navigation_bar" type="CheckButton" parent="VBoxContainer"]
87+
custom_minimum_size = Vector2(0, 60)
88+
layout_mode = 2
89+
theme_override_styles/pressed = SubResource("StyleBoxFlat_tvfxw")
90+
theme_override_styles/normal = SubResource("StyleBoxFlat_7vx7x")
91+
text = "LIght Navigation Bar"
92+
93+
[node name="status_bar_color" type="Button" parent="VBoxContainer"]
94+
custom_minimum_size = Vector2(0, 60)
95+
layout_mode = 2
96+
text = "Change Status Bar Color"
97+
98+
[node name="navigation_bar_color" type="Button" parent="VBoxContainer"]
99+
custom_minimum_size = Vector2(0, 60)
100+
layout_mode = 2
101+
text = "Change Navigation Bar Color"
102+
103+
[connection signal="color_changed" from="VBoxContainer/ColorPickerButton" to="." method="_on_color_picker_button_color_changed"]
104+
[connection signal="toggled" from="VBoxContainer/light_status_bar" to="." method="_on_light_status_bar_toggled"]
105+
[connection signal="toggled" from="VBoxContainer/light_navigation_bar" to="." method="_on_light_navigation_bar_toggled"]
106+
[connection signal="pressed" from="VBoxContainer/status_bar_color" to="." method="_on_button_pressed"]
107+
[connection signal="pressed" from="VBoxContainer/navigation_bar_color" to="." method="_on_button_2_pressed"]

plugin/export_scripts_template/SystemBarColorChanger.gd

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class_name SystemBarColorChanger extends Node
55

66
const _plugin_name: String = "SystemBarColorChanger"
77
var lightStatusBar: bool = false
8+
var lightNavigationBar: bool = false
89

910
var _plugin_singleton: Object
1011

@@ -22,7 +23,7 @@ func set_status_bar_color(color: Color):
2223

2324
func set_navigation_bar_color(color: Color):
2425
if _plugin_singleton:
25-
_plugin_singleton.setNavBarColor(change_color_format(color))
26+
_plugin_singleton.setNavBarColor(change_color_format(color),lightNavigationBar)
2627
else:
2728
printerr("%s singleton not found!" % _plugin_name)
2829

plugin/src/main/java/org/godotengine/plugin/android/systemBarColorChanger/SystemBarColorChanger.kt

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@ class SystemBarColorChanger(godot: Godot): GodotPlugin(godot) {
1212
override fun getPluginName() = BuildConfig.GODOT_PLUGIN_NAME
1313

1414
@UsedByGodot
15-
fun setNavBarColor(color: String) {
15+
fun setNavBarColor(color: String, lightNavBar: Boolean) {
1616
runOnUiThread {
1717
activity?.window?.navigationBarColor = Color.parseColor(color)
18+
val window = activity!!.window
19+
val wic = WindowInsetsControllerCompat(window, window.decorView)
20+
wic.isAppearanceLightNavigationBars = lightNavBar
1821
}
1922
}
2023

2124
@UsedByGodot
2225
fun setStatusBarColor(color: String, lightStatusBar: Boolean) {
2326
runOnUiThread {
2427
activity?.window?.statusBarColor = Color.parseColor(color)
25-
val currentTheme = activity!!.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
26-
when (currentTheme) {
27-
Configuration.UI_MODE_NIGHT_NO -> {
28-
val window = activity!!.window
29-
val wic = WindowInsetsControllerCompat(window, window.decorView)
30-
wic.isAppearanceLightStatusBars = lightStatusBar
31-
}
32-
}
28+
val window = activity!!.window
29+
val wic = WindowInsetsControllerCompat(window, window.decorView)
30+
wic.isAppearanceLightStatusBars = lightStatusBar
3331
}
3432
}
3533
}

0 commit comments

Comments
 (0)