3
votes

In my NativeScript project, I have a color defined in App_Resources/Android/src/main/res/values/colors.xml:

<resources>
    ...
    <color name="notification">#00546A</color>
</resources>

Now I try to access the value of the defined color like this:

utils.ad.getApplicationContext().getResources().getColor(
    android.R.color.notification, 
    null
)

But I always get:

android.content.res.Resources&NotFoundException: Resource ID #0x0

I also tried:

android.support.v4.content.ContextCompat.getColor(
    utils.ad.getApplicationContext(), 
    android.R.color.notification
)

... but same result.

Does anybody have a hint?

1

1 Answers

3
votes

Try this

var app = require('tns-core-modules/application');
app.getNativeApplication().getResources().getIdentifier("color_name", "color", app.getNativeApplication().getPackageName());