Android Question Customising Native UI Themes

RichardN

Well-Known Member
Licensed User
Longtime User
After my experiences with the API36 transition I thought it might be interesting to have a small collection of custom UI themes for future projects. I understand this involves customising one the exisiting native themes at compile-time in the manifest. Using examples from the forum I have the bones of creating a 'child-theme' but I have so far failed to get the code to compile and the errors are not very informative as to the cause. Interaction with the existing themes seems to be the issue. Help appreciated.....

B4X:
' ==============================================================================
' DEFINE THE THEME COLOR PALETTE

SetApplicationAttribute(android:theme, "@style/LightTheme")

CreateResource(values, colors.xml,
<resources>
    <color name="mint_primary">#3EB489</color>
    <color name="mint_primary_dark">#2C8563</color>
    <color name="mint_accent">#50E3C2</color>
    <color name="mint_background">#F4F9F6</color>   
    <color name="mint_text">#1A2E26</color>
</resources>
)

' ==============================================================================
'CREATE THE LIGHT MINT THEME CONFIGURATION

CreateResource(values, theme.xml,
<resources>
    <!-- Inherits from the standard native Light theme with no title bar -->
    <style name="CustomLightMintTheme" parent="Theme.Material.Light">        '*** Fails on this line
        <!-- Apply custom color tokens into standard system variables -->
        <item name="colorPrimary">@color/mint_primary</item>
        <item name="colorPrimaryDark">@color/mint_primary_dark</item>
        <item name="colorAccent">@color/mint_accent</item>
        <item name="android:windowBackground">@color/mint_background</item>
        <item name="android:textColor">@color/mint_text</item>
    </style>
</resources>
)

' ==============================================================================
' 3. APPLY THE THEME APPLICATION-WIDE

SetApplicationAttribute(android:theme, "@style/CustomLightMintTheme")
 

RichardN

Well-Known Member
Licensed User
Longtime User
B4A Version: 13.70 BETA #1
Parsing code. (0.00s)
Java Version: 19
Building folders structure. (0.04s)
Compiling code. (0.01s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Compiling resources (0.11s)
Linking resources Error
error: resource style/Theme.Material.Light (aka b4a.example:style/Theme.Material.Light) not found.
res\values\theme.xml:6: error: style attribute 'attr/colorPrimary (aka b4a.example:attr/colorPrimary)' not found.
res\values\theme.xml:7: error: style attribute 'attr/colorPrimaryDark (aka b4a.example:attr/colorPrimaryDark)' not found.
res\values\theme.xml:8: error: style attribute 'attr/colorAccent (aka b4a.example:attr/colorAccent)' not found.
error: failed linking references.

It would seem that the attributes colorPrimary, colorPrimaryDark and colorAccent are not supported by Theme.Material.Light so the code fails. With each theme apparently supporting different colour references it becomes very difficult to define a child theme that you can work from. The Statusbar also tends to be white on white with API36 whatever you do with the manifest settings.
 
Last edited:
Upvote 0
Top