Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using an Android Library Project how do you reference xml resources properly?

I have an Android Library Project that contains several styles/themes defined in its styles.xml file.

Normally, when referencing this style in some other xml layout or manifest file, you would just write android:theme="@style/TheNameOfTheStyle"

When using a library project, how does the dependent project properly reference that style now? Just leaving it as android:theme="@style/TheNameOfTheStyle" gives me an error saying there is no resource found matching that name.

I guess this same question applies for other references like @string, @color etc.

Thanks

Edit: Ok so it appears that you are suppose to reference it just like normal, but the console in eclipse is giving me this error:

Error: No resource found that matches the given name (at 'theme' with value '@style/ThemeName').

(facepalm) Edit

I just needed to "Clean Project" in Eclipse. Now it's working.

like image 888
cottonBallPaws Avatar asked Jan 30 '11 22:01

cottonBallPaws


People also ask

How is XML used in Android?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.

Where is XML used in Android?

eXtensible Markup Language, or XML: A markup language created as a standard way to encode data in internet-based applications. Android applications use XML to create layout files. Unlike HTML, XML is case-sensitive, requires each tag be closed, and preserves whitespace.

What is XML code in Android Studio?

XML stands for eXtensible Markup Language, which is a way of describing data using a text-based document. Because XML is extensible and very flexible, it's used for many different things, including defining the UI layout of Android apps.

Where is the main XML file in Android Studio?

xml extension, in your Android project's res/layout/ directory, so it will properly compile. More information about the syntax for a layout XML file is available in the Layout Resources document.


2 Answers

Its important to build the project after adding resources (or just have autobuild on) and cleaning the project helps most of the times. Restarting Eclipse when "something" go wrong is a good idea, too.

Also note that Android merges the recources, so the last project that is build "wins" the name. For this reason it's a good idea to prefix ALL resources somehow.

like image 199
Rafael T Avatar answered Oct 23 '22 22:10

Rafael T


I use IntelliJ and what worked for me is to reference the resource normally and to make sure the library is added as a dependency of the project

like image 37
AlanKley Avatar answered Oct 23 '22 23:10

AlanKley