Kurru Kurru - 1 year ago 26
Android Question

Styling Custom Views

I have a few custom views in my Android project and I've added the relevant details to the attrs.xml file. And now I can implement my objects through XML. This works fine.

How do I style these elements? When I try to use my custom attributes in the styles.xml is get an error "No resource found that matches the given name:"

For using the custom views in normal xml developement I use xmlns:app="http://schemas.android.com/apk/res/bla.bla.bla". What is the correct for use in styles?

This is what my style looks like currently

<style name="Journey_DaySelect_Sunday">
<item name="app:onImage">@drawable/day_sunday_selected</item>
<item name="app:offImage">@drawable/day_sunday</item>

Answer Source

After more intensive searching on Google I gave up finding it answered elsewhere, and by chance tried using the absolute namespace of my generated R file it worked. May this solve all your problems.


<style name="Journey_DaySelect_Sunday" parent="Journey_DaySelect">
    <item name="AppZappy.NIRailAndBus:onImage">@drawable/day_sunday_selected</item>
    <item name="AppZappy.NIRailAndBus:offImage">@drawable/day_sunday</item>