Android Code Snippet Change notification background color

Hi
How Can I Change Notification Background Color? :)

Like the picture below ?

thBADT5EQY.jpg


Thanks in advance for your help ;)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1585746916923.png


Add to NB6:
B4X:
'Whether to use the accent color for the background. Not applied in all cases.
'For most styles, the coloring will only be applied if the notification is for a foreground service notification.
Public Sub Colorized (Enabled As Boolean) As NB6
    If IsBuilder Then
        If SdkLevel >= 26 Then
            NotificationBuilder.RunMethod("setColorized", Array(True))
        End If
    End If
    Return Me
End Sub

Usage example:
B4X:
Sub Service_Create
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
    Dim icon As Bitmap = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(icon).Color(Colors.Red).Colorized(True)
    Service.StartForeground(10, n.Build("Colorized", "This is a foreground service notification", "tag1", Me))
End Sub
 
Top