I have a question concerning the Dark theme that has been introduced with Android 10.
What is the best practice to support Dark themes in B4A?
How can I select an image based on the night mode flag?
If you use the default colors then most views will look properly automatically.
You can check whether night mode is active:
B4X:
Sub IsNightMode As Boolean
Dim ctxt As JavaObject
ctxt.InitializeContext
Log(ctxt.RunMethodJO("getResources", Null).RunMethodJO("getConfiguration", Null).GetField("uiMode"))
Return Bit.And(ctxt.RunMethodJO("getResources", Null).RunMethodJO("getConfiguration", Null).GetField("uiMode"), 0x30) = 0x20
End Sub
You can set the default night mode if you don't want it to be based on the system default:
B4X:
Sub SetDefaultNightMode (Mode As Int)
Dim jo As JavaObject
jo.InitializeStatic("androidx.appcompat.app.AppCompatDelegate").RunMethod("setDefaultNightMode", Array(Mode))
End Sub