B4J Question [ABMaterial] How to use RGB color in ABMaterial

incendio

Well-Known Member
Licensed User
Longtime User
Hello guys,

I have been used colors predefined in ABMaterial, such as ABMaterial.COLOR_GREY, etc.

Is that possible to use RGB color in ABMaterial & if possible, how to use it, for example if I want to apply color with RGB 122(Red),30(Green),30(Blue).

Thanks in advance.
 

alwaysbusy

Expert
Licensed User
Longtime User
Material Design uses palettes to define colors. This is because in some controls when you define 'red', the library must be able to create a darker or lighter version of this red. By default a couple of palettes are build-in ABMaterial, but you can build your own pallet

You can create your own colors/palettes with an Alpha channel. Note that it has to be set for every INTENSITY you are going to need:

tmpTheme.Page.AddColorDefinition("myred", ABM.INTENSITY_DARKEN4, "#B71C1C", 0.18)
tmpTheme.Page.AddColorDefinition("myred", ABM.INTENSITY_LIGHTEN2, "#B71C1C", 0.18)

Then you can use it as:

tmpTheme.Container("zdepthred").BackColor = "myred"
tmpTheme.Container("zdepthred").BackColorIntensity = ABM.INTENSITY_DARKEN4
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I use these codes
B4X:
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_DARKEN1,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_DARKEN2,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_DARKEN3,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_DARKEN4,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_LIGHTEN1,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_LIGHTEN2,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_LIGHTEN3,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_LIGHTEN4,"A0A0A0",1)
MyTheme.Page.AddColorDefinition("mygrey",ABM.INTENSITY_LIGHTEN5,"A0A0A0",1)
MyTheme.Container("zdepthgrey").BackColor = "mygrey"
MyTheme.Container("zdepthgrey").BackColorIntensity = ABM.INTENSITY_DARKEN4
Got error :
abmshared._vvv4 (java line: 244)
java.lang.NullPointerException
at b4j.example.abmshared._vvv4(abmshared.java:244)
at b4j.example.main._appstart(main.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
It probably is because you've used A0A0A0 instead of #A0A0A0 (note that in your definition all intensities will have the same color, but maybe that is your intention).

also try running it in debug mode, as I think it now runs in obfuscated mode (vvv4). Maybe we get a better clue of what could be wrong.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
It probably is because you've used A0A0A0 instead of #A0A0A0 (note that in your definition all intensities will have the same color, but maybe that is your intention).

also try running it in debug mode, as I think it now runs in obfuscated mode (vvv4). Maybe we get a better clue of what could be wrong.
I have used #A0A0A0 & run in Debug Mode.
The error point to these codes
B4X:
MyTheme.Container("zdepthgrey").BackColor = "mygrey"
MyTheme.Container("zdepthgrey").BackColorIntensity = ABM.INTENSITY_DARKEN4
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
it has to have a # prefix for sure.

But do you have a container control theme called zdepthgrey? (this was just an example)
e.g. in my code I would have created a container theme using:

B4X:
MyTheme.AddContainerTheme("zdepthgrey") '<--
MyTheme.Container("zdepthgrey").BackColor = "mygrey"
MyTheme.Container("zdepthgrey").BackColorIntensity = ABM.INTENSITY_DARKEN4

And then when the container was created, I would've used this theme, like I would any other:

B4X:
dim cont as ABMContainer
cont.Initialize(page, "cont", "zdepthgrey")
...
 
Upvote 0
Top