Android Question How To Change Title Bar Color with Code

Sofian

Member
Hi all, I want to change theme color with code. But not successful to change title bar color. my code :
code1:
Sub SetStatusBarColor(clr As Int)
     Dim p As Phone
    If p.SdkVersion >= 21 Then
        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("setStatusBarColor", Array(clr))
        window.RunMethod("setNavigationBarColor", Array(clr))
   
    End If
End Sub


Private Sub ImageView1_Click
    SetStatusBarColor(Rnd(0xFF000000, 0))
End Sub

result as picture attacth below , please help
 

Attachments

  • WhatsApp Image 2023-01-27 at 16.39.39.jpeg
    WhatsApp Image 2023-01-27 at 16.39.39.jpeg
    47.4 KB · Views: 67
  • WhatsApp Image 2023-01-27 at 16.32.10.jpeg
    WhatsApp Image 2023-01-27 at 16.32.10.jpeg
    46.6 KB · Views: 73

William Lancee

Well-Known Member
Licensed User
Longtime User
Another approach us to remove the native title bar completely and make your own panel with stuff in it - you can control everything.

In Main
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region
 
Upvote 0

Sofian

Member
Another approach us to remove the native title bar completely and make your own panel with stuff in it - you can control everything.

In Main
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region
thanks for replay, I will try with this solution
 
Upvote 0
Top