Android Question Transparent white icon is not seen on white background

scsjc

Well-Known Member
Licensed User
Longtime User
I would like to know how to make the icon visualize with a white line, and when the app background is white it will continue to be displayed.

I use this code in the notification, and I choose the icon inside the folder ... objects / res / drawable / icon.png


B4X:
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icono"
icono:

1580816431406.png


result:

1580816170250.png
 

scsjc

Well-Known Member
Licensed User
Longtime User
i would not set the nav bar to white color at all.
The Icon color can not be changed as far as i know. They are always white

If I put a color icon, I get in the color status of the icon.

But I want it to go white when the status background is dark, and go black when the status background is clear.

The problem is that if I paint the icon in white, it always comes out in white, or if I paint it in black it always comes out in black.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
or use both colors so that you have a boxed black image with white circle/F in it.

on black you'll see the white circle/F.
on white you'll see the black box with circle/F cut out.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could try something like this, which dependant on the phone having Android release 21+, will read the status bar colour and return a contrasting colour (Black or White) or Gray if release is < 21.

B4X:
Sub GetIconColor 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))
        Return ContrastColor(window.RunMethod("getStatusBarColor", Null))
    End If
    Return Colors.Gray
End Sub
Public Sub ContrastColor(Color As Int) As Int
    'From https://stackoverflow.com/a/41335343
    'Counting the perceptive luminance - human eye favors green color...
    '                                        Red                                           Green                                       Blue
    Dim A As Double = 1 - (0.299 * Bit.And(Bit.ShiftRight(Color,16),0xFF) + 0.587 * Bit.And(Bit.ShiftRight(Color,8),0XFF) + 0.114 * Bit.And(Color,0xFF)) / 255
    If A < 0.5 Then
        Return Colors.Black
    Else
        Return Colors.White
    End If
End Sub

Code from here : https://www.b4x.com/android/forum/threads/statusbar-color.65600/post-415530
and here : https://www.b4x.com/android/forum/threads/b4x-contrast-background-and-text-colors.112963/post-704523

Reference : https://developer.android.com/reference/android/view/Window
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
are you sure there isn't a difference made between the top icon and the one in the full message?
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
are you sure there isn't a difference made between the top icon and the one in the full message?
putting # 888888 if it looks above (dark envelope) and in whole message (light envelope) as I show in the screenshot. but being a gray, it looks poor.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
You could try something like this, which dependant on the phone having Android release 21+, will read the status bar colour and return a contrasting colour (Black or White) or Gray if release is < 21.

B4X:
Sub GetIconColor 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))
        Return ContrastColor(window.RunMethod("getStatusBarColor", Null))
    End If
    Return Colors.Gray
End Sub
Public Sub ContrastColor(Color As Int) As Int
    'From https://stackoverflow.com/a/41335343
    'Counting the perceptive luminance - human eye favors green color...
    '                                        Red                                           Green                                       Blue
    Dim A As Double = 1 - (0.299 * Bit.And(Bit.ShiftRight(Color,16),0xFF) + 0.587 * Bit.And(Bit.ShiftRight(Color,8),0XFF) + 0.114 * Bit.And(Color,0xFF)) / 255
    If A < 0.5 Then
        Return Colors.Black
    Else
        Return Colors.White
    End If
End Sub

Code from here : https://www.b4x.com/android/forum/threads/statusbar-color.65600/post-415530
and here : https://www.b4x.com/android/forum/threads/b4x-contrast-background-and-text-colors.112963/post-704523

Reference : https://developer.android.com/reference/android/view/Window
I didn't know it would be so complicated to put the icon in notification.

I thought the system managed to put it in black or white depending on the situation.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That is a different question, I haven't used them so I can't answer that. Perhaps check on Android Developers site to see if that is the standard behaviour.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tested with the white icon:

i_view64_jYDLpOOVag.png


Unless you are using an old version of Android, the icon colors shouldn't matter as the image is used as a mask.

B4X:
Dim nb As NB6
nb.Initialize("id", "my channel", "DEFAULT")
nb.SmallIcon(LoadBitmapResize(File.DirAssets, "icono.png", 24dip, 24dip, False))
nb.Build("Test", "Test", "", Me).Notify(1)
 
Upvote 0
Top