5

Is it possible to use more CSSes in the same Codename One project?

Use case 1: I want different styles in different parts of the app or I want to replace at all the current styling.

Use case 2: I want that the current style is derived from several CSSes, like in a web page

Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23
  • Yes, it is possible. I have done it on my website. It's location is hinted about in my profile. You can load multiple stylesheets and either select them from the alternate styles menu in the browser, or via JavaScript style switching. – hellork Nov 27 '18 at 07:11
  • @hellork Your comment is not related to Codename One. The CSS support by Codename One is different from a browser. – Francesco Galgani Nov 27 '18 at 17:40
  • @Francesco Hi. Did you add a new css file to to the css folder or did you create a new theme after clicking theme.res? I'm trying to implement multiple css files in my project as well but am not sure which steps to take. Thanks. – app-dev Mar 13 '19 at 17:14
  • I'm using multiple CSSes without problems. Add the CSS files to the css folder, modify the `build.xml` as in Shai's answer. When you compile and run the project, for each css it will be generated a new .res file, as specified in the build.xml. In the `init()` of the main class you should have a code to load multiple themes. I created this example code for you: https://gist.github.com/jsfan3/b001fdfa07a1a5a93600960ce1171e5f – Francesco Galgani Mar 13 '19 at 17:29
  • Moreover, remember to add `includeNativeBool: true;` only on the first CSS. – Francesco Galgani Mar 13 '19 at 17:42
  • Thanks so much! – app-dev Mar 18 '19 at 17:42

1 Answers1

3

There is currently no support for that in the CSS implementation that's integrated into the plugin. The old implementation allowed that but we simplified some things so the conversion process will be fluid.

Since multiple resource files and layered themes are supported internally by Codename One this should probably be easy to accomplish. I'm guessing something like this in the build.xml might work:

<target name="-cn1-compile-css" if="codename1.cssTheme">
        <java jar="${user.home}/.codenameone/designer_1.jar" failonerror="true">
            <jvmarg value="-Dcli=true"/>
            <arg value="-css"/>
            <arg file="css/theme.css"/>
            <arg file="src/theme.res"/>
        </java>
        <java jar="${user.home}/.codenameone/designer_1.jar" failonerror="true">
            <jvmarg value="-Dcli=true"/>
            <arg value="-css"/>
            <arg file="css/second-theme.css"/>
            <arg file="src/second-theme.res"/>
        </java>
    </target>
</project>
Shai Almog
  • 51,749
  • 5
  • 35
  • 65