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

Discussion in 'B4J Questions' started by incendio, Aug 30, 2017.

  1. incendio

    incendio Well-Known Member Licensed 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.
     
  2. alwaysbusy

    alwaysbusy Expert Licensed 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
     
  3. incendio

    incendio Well-Known Member Licensed User

    I use these codes
    Code:
    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)
     
  4. alwaysbusy

    alwaysbusy Expert Licensed 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.
     
  5. incendio

    incendio Well-Known Member Licensed User

    I have used #A0A0A0 & run in Debug Mode.
    The error point to these codes
    Code:
    MyTheme.Container("zdepthgrey").BackColor = "mygrey"
    MyTheme.Container(
    "zdepthgrey").BackColorIntensity = ABM.INTENSITY_DARKEN4
     
  6. alwaysbusy

    alwaysbusy Expert Licensed 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:

    Code:
    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:

    Code:
    dim cont as ABMContainer
    cont.Initialize(
    page"cont""zdepthgrey")
    ...
     
    incendio likes this.
  7. alwaysbusy

    alwaysbusy Expert Licensed User

    @incendio I apologize that sometimes when I write an answer I skip some steps as for me I'm so used to the framework, I forget for other a lot of this is new :oops:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice