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.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			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 
				 
 
		 
 
		 
 
		 
						
					 
 
		 
 
		