CrepuscularV
CrepuscularV

Reputation: 1043

How to access the resource files under a self-defined resource directory?

The Android Project Resource directories are located at,

app/src/main/res/drawable
app/src/main/res/layout
app/src/main/res/values

...

Suppose I would like to add a source file as,

app/src/main/res/myRes/res001.xml

Is it possible to read the resource info from my code? or my resource files are strictly restricted to the supported resource directories?

Upvotes: 0

Views: 1147

Answers (3)

TeChNo_DeViL
TeChNo_DeViL

Reputation: 739

Custom resources are not supported by Android. You must use any of the predefined structure folders of Android. If you still would like to add custom resources use /res/xml for xml resources and /res/assets for all other resources like fonts, text files etc.

This link may help

Upvotes: 1

Jacob Nordfalk
Jacob Nordfalk

Reputation: 3533

You'll have to decide on a type.

Androids resource system have specific directories for specific resource types. You can't just 'add a resource', you have to decide on the type, for example:

  • a layout file res/layout/main.xml
  • a generic XML file (which will be compressed) res/xml/somedata.xml, or
  • a raw type (which will also be compressed, unless you name it with an uncompressable extension, like for example MP3) res/raw/mydata.json

That being said you can make gradle do anything, like for example include several resource directories, like main/res and release/res

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007484

Suppose I would like to add a source file as app/src/main/res/myRes/res001.xml

You should get a compile error, as you cannot invent new resource types. Either put that file in res/xml/ (which can handle any sort of XML), res/raw/ (which can handle any sort of file), or assets/.

Upvotes: 2

Related Questions