NICQITA
NICQITA

Reputation: 11

How to use your own XML resource in Android

I have my own XML files in a ./values folder. However I have no idea how to use/ call them. Any suggestions?

Upvotes: 0

Views: 718

Answers (2)

kds23
kds23

Reputation: 306

  1. Create a folder called "xml" inside your res folder.
  2. Place your xml file there, say yourfile.xml
  3. Use it in xml as:

    < include layout="@xml/yourfile" android:id="@+id/yourXmlId" />

You can also use it in Java as:

XmlPullParser yourXml = getResources().getXml(R.xml.yourfile);

You could also place the xml file in other folders like "layout", "drawable", "anim", "dimen" etc., depending on your use case or requirement.

Upvotes: 2

Suhail k k
Suhail k k

Reputation: 66

Can you mention what is the purpose of that xml?Is it created for creating background?I f you created it for drawing some shapes or your on images,please put it in drawable(res/drawable) folder.If your xml is for color,config,dimension,string,or style, put inside res/values folder.You can also create xml for menu related stuffs.Such xml can be put inside menu folder.

Upvotes: 0

Related Questions