Android Question SetNavigationBarColor And Icon

mt_heka

Member
In my last thread: Resize Root B4XPages (Height Same Activity)
We found a way to add the statusbar height to an activity and display it in B4XPages. The problem was that after applying this display, I couldn't change their NavigationBarColor and theme icon.

#In_Activity:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public CorrectHeight As Int
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 4.4 Then
        Dim jo As JavaObject
        Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
        window.RunMethod("addFlags", Array(Bit.Or(0x00000200, 0x08000000)))
        Activity.Height = Activity.Height + GetStatusBarHeight
        Activity.Color = Colors.Green 'for show
        CorrectHeight = Activity.Height + GetStatusBarHeight
    End If
    
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
End Sub

Public Sub GetStatusBarHeight As Int
    Dim jo As JavaObject
    jo.InitializeContext
    Dim resources As JavaObject = jo.RunMethod("getResources", Null)
    Dim resId As Int = resources.RunMethod("getIdentifier", Array("status_bar_height", "dimen", "android"))
    If resId > 0 Then
        Return resources.RunMethod("getDimensionPixelSize", Array(resId))
    Else
        Return 0
    End If
End Sub

#In_B4XPages:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    'Theme
    SetNavigationBarColor(Colors.Red) 'not work!
    SetIconBarsColor(False)  'not work!
End Sub

Private Sub B4XPage_Appear
    Root.Height = Main.CorrectHeight
End Sub

Sub SetIconBarsColor(DarkIcon As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 21 Then
        Dim jo As JavaObject
        jo.InitializeContext
        Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
        Dim view As JavaObject = window.RunMethodJO("getDecorView",Null)

        If DarkIcon = True Then
            'Light style with Black icons and text
            view.RunMethod("setSystemUiVisibility",Array(Bit.Or(0x00002000,view.RunMethod("getSystemUiVisibility",Null)))) 'Light style with black icons and text
        Else
            'Dark style with White icons and text
            view.RunMethod("setSystemUiVisibility",Array(0))
        End If
    End If
End Sub

Sub SetNavigationBarColor (Color As Int)
    Dim sdk As Phone
    If sdk.SdkVersion >= 21 Then
        Dim j1 As JavaObject
        j1.InitializeContext
        j1.RunMethodJO("getWindow",Null) _
            .RunMethod("setNavigationBarColor",Array (Color))
    End If
End Sub
 

Attachments

  • Project.zip
    14.4 KB · Views: 66

mt_heka

Member
1.
Remove the FLAG_TRANSLUCENT_NAVIGATION flag
B4X:
window.RunMethod("addFlags", Array(0x00000200)) 'FLAG_LAYOUT_NO_LIMITS

This will allow you to change the navigation bar color.

2. The call to SetIconBarsColor is problematic as it changes the navigation bar theme and overrides the custom color.
nothing change!!:
1. I Remove the FLAG_TRANSLUCENT_NAVIGATION flag
#In_Activity:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public CorrectHeight As Int
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 4.4 Then
        Dim jo As JavaObject
        Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
        window.RunMethod("addFlags", Array(0x00000200)) 'FLAG_LAYOUT_NO_LIMITS
        Activity.Height = Activity.Height + GetStatusBarHeight
        Activity.Color = Colors.Green 'for show
        CorrectHeight = Activity.Height + GetStatusBarHeight
    End If
   
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
End Sub

Public Sub GetStatusBarHeight As Int
    Dim jo As JavaObject
    jo.InitializeContext
    Dim resources As JavaObject = jo.RunMethod("getResources", Null)
    Dim resId As Int = resources.RunMethod("getIdentifier", Array("status_bar_height", "dimen", "android"))
    If resId > 0 Then
        Return resources.RunMethod("getDimensionPixelSize", Array(resId))
    Else
        Return 0
    End If
End Sub

and i don't use SetIconBarsColor but still I can't change the navigation bar color...
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
??
1.gif
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
OTHER:
1 (1).gif
 
Upvote 0

mt_heka

Member
OTHER:
View attachment 163873
I don't want change StatusBarColor I want change NavigationBarColor after resize root (add StatusBa Height to ativity and root too)

this resource: https://www.b4x.com/android/forum/threads/transparent-statusbar-using-b4xpages.125562/#post-784203
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see and search:
search:
 
Upvote 0
Top