Android Question Bottom up Popup Drawer darken status and title

scsjc

Well-Known Member
Licensed User
Longtime User

Does it refer to something like this? or can it be improved?



B4X:
Sub ToggleDrawerState
    Dim Duration As Int = 100
    
    OverlayVisible = Not(OverlayVisible)
    Overlay.SetVisibleAnimated(Duration, OverlayVisible)
    
    Dim pnlBottomVisibleHeight As Int = pnlBottom.Height - 8dip 'hide bottom round corners
    
    If OverlayVisible Then
        SetActionBarColor(Colors.ARGB(150, 0, 0, 0))
        SetStatusBarColor( mixColors(Colors.ARGB(150, 0, 0, 0), Colors.black) )
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
    Else
        SetActionBarColor(Colors.Transparent)
        SetStatusBarColor(Colors.ARGB(150, 0, 0, 0))
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
    End If
End Sub

Sub SetStatusBarColor(Color As Int)
    'status
    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(Color))
End Sub

Sub SetActionBarColor(Color As Int)
    'menu bar
    Dim jo As JavaObject
    jo.InitializeContext
    Dim cd As ColorDrawable
    cd.Initialize(Color, 0)
    jo.RunMethodJO("getActionBar", Null).RunMethod("setBackgroundDrawable", Array(cd))
End Sub
 

Attachments

  • B4XBottomSheet.zip
    12.8 KB · Views: 66
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
The code looks good. You can probably improve it by modifying the class code and making the change more gradual.
Thank you very much as always your good advice is greatly appreciated
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…