Kris Campos Kris Campos - 1 month ago 5
Android Question

How to reference custom resource-file in xml

How does you register a custom xml-resource-file with android studio so that you can reference it from other xml files?

I understand that its possible to call values from new resource values programmatically using R but I was wondering if there was a way to do that statically from another XML file.

For example, referencing that new file (in this case called keys.xml) in another xml file

android:value="@keys/MAPS_API_KEY" />

as opposed to using strings.xml


Just create a resource file like:


<?xml version="1.0" encoding="utf-8"?>
    <string name="testKey">TEST_VALUE</string>

In code, you can call:


From another xml:


The trick is you declare as a <resources> in your xml file.