Issue
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
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@keys/MAPS_API_KEY" />
as opposed to using strings.xml
Edit: It turns out that @string does NOT specifically reference strings.xml. I was originally under the impression that it did and knowing that know makes my question seem a tad silly.
Solution
Just create a resource file like:
keys.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="testKey">TEST_VALUE</string>
</resources>
In code, you can call:
getString(R.string.testKey);
From another xml:
<TextView
...
android:text="@string/testKey"
...
/>
The trick is you declare as a <resources>
in your xml file.
Answered By - Adley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.