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() ?
Create a new custom XML file by selecting File > New or by clicking the Create a new custom XML file link in the right-hand pane. The New Custom File dialog is displayed. 3. Save the new custom XML file by selecting File > Save As and then specifying the name and location of the file.
You are changing values in file which is generated by Android Studio, so it is changed every time you build your project. All files inside build folders are generated and there is no need in changing them. Instead you should put your values in values. xml under app->src->main->res->values .
Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. You can also use Android Studio's Layout Editor to build your XML layout using a drag-and-drop interface.
The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.
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:-

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With