I want to add a custom xml which having URLs to the res/values folder. I can add the file but how to read its content by getResources() ?
Yes you can have a custom file: I just did this a couple of times. 1) Make a new xml file. 2) Use file format as as wrapper for yours Example:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<item name="languages">
<languages>
<language>
<isocode>
en-UK
</isocode>
<name>
English (UK)
</name>
</language>
</languages>
</item>
</resources>
Update: This doesn't seem to work anymore (but it used to) and you cannot create your own custom types in android. Only the standard available resource types work now.
Therefore, the only way to achieve something like this would be, have your separate file as suggested, url.xml and have all yours URLs in that file so that it doesn't get mixed up with the other Strings. It just improves readability and maintainability, AFAIK.
The URL item now looks like,
<item name="myUrl" type="string">http://myUrl.com</item>
And you needs to be accessed the usual way:
String myurl = getResources().getString(R.string.myUrl);
Original Answer:
Try something like this:-
url.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="myUrl" type="urls">http://myUrl.com</item>
</resources>
And in your activity, get it like this:-
String s = getResources().getString(R.urls.myUrl);
Note:- You needn't register your xml
anywhere. Just make sure its available in res/values
folder.
Snapshot:-