Android Code Snippet SetNavigationBarColor - Change code of Navigation Bar by Code

I use this function to change color of the Navigation Bar (SDK > 21 = Android 5+) in some screens of my app that use Theme.Holo.Light.
B4X:
Sub SetNavigationBarColor(clr As Int)
    Dim p As Phone
    If p.SdkVersion >= 21 Then  'versão 5.0
        Dim jo As JavaObject
        jo.InitializeContext
        Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
        window.RunMethod("addFlags", Array (0x80000000))
        window.RunMethod("clearFlags", Array (0x04000000))
        window.RunMethod("setNavigationBarColor", Array(clr))
    End If
End Sub
 
Last edited:

asales

Expert
Licensed User
Longtime User
Unless you want to change the color at runtime then it is better to change them in the manifest editor: https://www.b4x.com/android/forum/threads/theme-colors.87716/
This way they will look correctly right when the app becomes visible.

Thanks, but this aproach is compatible with the "Theme.Holo.Light"?
I'm tried to use the code:
B4X:
<color name="navigationBar">#ff006db3</color>
in this style:

B4X:
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
       <item name="android:navigationBarColor">@color/navigationBar</item>
without success.
 
Top