I do according to documentation
module common created
res/values/public.xml
<resources>
<public name="app_name" type="string"/>
</resources>
Also tried
<resources>
<public/>
</resources>
res/values/strings.xml
<resources>
<string name="app_name">app_name</string>
<string name="app_name_2">app_name_2</string>
</resources>
Also tried without public.xml
res/values/strings.xml
<resources>
<public name="app_name" type="string"/>
<string name="app_name">app_name</string>
<string name="app_name_2">app_name_2</string>
</resources>
<resources>
<public />
<string name="app_name">app_name</string>
<string name="app_name_2">app_name_2</string>
</resources>
module app can use private resources
android.example.common.R.string.app_name_2
I think the problem is from Android Developers side, because their video says how private resources should work, but they don't work that.
That's why I created an IssueTracker request, everyone who is affected can vote (upper right corner) so that Google pays attention to the error.
Related
This question already has answers here:
Android xml reference within xml doesn't work
(2 answers)
Closed 5 years ago.
I'm trying to set an XML attribute with a variable in the resources in Android studio with no luck.
Something like this works:
<resources>
<string name="Key">#string/Key</string>
</resources>
But something like this doesn't:
<resources>
<string name="Key" custom-attribute="#string/Key"/>
</resources>
How do you use variables in XML attributes?
This is NOT the same question as Android xml reference within xml doesn't work.
The first example works correctly, I am able to use variables setting a field value. The second example does not work, I cannot set an attribute.
<resources>
<string name="Key">Some Value</string>
</resources>
Should give you same result as:
<resources>
<string name="Key" value="Some Value"/>
</resources>
Because of that I would recommend using the first example as that works properly.
Try this:
<string name="Key1">Some Text</string>
<string name="Key2">#string/Key1</string>
update:
<string name="Key1">Some Text</string>
<string name="Key2">
<some-attribute>#string/Key1</some-attribute>
</string>
Here we can define resources in res/ folder.
You can create your own file and use below examples.
The value thing won't work.
<resources>
<string name="button">Try Again</string>
<dimen name="margin">56dp</dimen>
<bool name="isCorrect">false</bool>
<color name="background">#fff</color>
<drawable name="icon">#drawable/ic_about_us</drawable>
<integer name="count">56</integer>
<string-array name="days">
<item>Monday</item>
<item>Sunday</item>
</string-array>
</resources>
And Use by R.id.nameOfResource
Here is much more to explore about them.
Hope this helps.
Update: We can also define resources like this in build.gradle script.
android {
buildTypes.each {
it.resValue 'string', 'serverLink', "https://mylink.com"
}
}
Is there a way how to add comment/description/documentation to android resource reference? The only way I know is to use standart XML comment. Which is not ideal obviously.
Something like special attribute or special javadoc pre-element
<resources>
<string documentation="Some useful information what does this resource means..." name="KEY" translatable="false">value</string>
</resources>
<resources>
<documentation forName="KEY">Some useful information what does this resource means...</documentation>
<string name="KEY" translatable="false">value</string>
</resources>
Not ideal but currently functional way:
<resources>
<!-- Some useful information about what this resource means... -->
<string name="KEY" translatable="false">value</string>
</resources>
The following format allows for a file header (using XML documentation comments), as well as as an individual comment (a documentation attribute) that goes along with each resource entry. I haven't had the compiler complain that a specific namespace (other than xmlns:tools) that contains documentation is required.
<?xml version="1.0" encoding="utf-8"?>
<!--=============================================================================================
My File description here
==============================================================================================-->
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="Application_Name" documentation="Name of the application. Used as Activity Name as the title, and appears in About box">FantasticApp</string>
</resources>
I´m currently creating an free Material Design Icon Pack following [this][1] tutorial (I don´t have much experience in coding) in Eclipse. After I added some of my Icons to the applifter.xml and declared them in the iconpack.xml I get this Error when I´m trying to build it:
[2015-02-26 16:10:35 - Materialism] C:\Users\...\workspace\Materialism\res\values\iconpack.xml:10: error: Error parsing XML: junk after document element
[2015-02-26 16:10:35 - Materialism]
[2015-02-26 16:10:35 - Materialism] C:\Users\...\workspace\Materialism\res\xml\appfilter.xml:12: error: Error parsing XML: junk after document element
[2015-02-26 16:10:35 - Materialism]
[2015-02-26 16:12:30 - Materialism] Error in an XML file: aborting build.
It says "the markup in the document following the root document must be well formed"
This is my applifter.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<iconback img1="iconback" />
<iconmask img1="iconmask" />
<iconupon img1="iconupon" />
<scale factor="1.1" />
<!-- Browser -->
<item component="ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
<item component="ComponentInfo{com.google.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
</resources>
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster"
<item component="ComponentInfo{com.devhd.feedly/com.devhd.feedly.Main}" drawable="feedly"
<item component="ComponentInfo{com.rhapsody.napster/com.rhapsodycore.SplashScreen}" drawable="napster"
<item component="ComponentInfo{com.netflix.mediaclient/com.netflix.mediaclient.UIWebViewActivity}" drawable="netflix"
<item component="ComponentInfo{com.android.stk/com.android.stk.StkMenuActivity}" drawable="simtoolkit"
<item component="ComponentInfo{com.snapchat.android/com.snapchat.android.LandingPageActivity}" drawable="snapchat"
<item component="ComponentInfo{com.rarlab.rar/com.rarlab.rar.MainActivity}" drawable="rar"
<item component="ComponentInfo{com.keramidas.TitaniumBackup/com.keramidas.TitaniumBackup.MainActivity}" drawable="titaniumbackup"
And the iconpack.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="icon_pack" translatable="false">
<item>com_android_browser_browseractivity</item>
</string-array>
</resources>
<string-array name="icon_pack" translatable="false">
<item>bassbooster</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>feedly</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>napster</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>netflix</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>rar</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>simtoolkit</item>
</string-array>
How can I resolve this?
Thank in advance :-)
XML files have a strictly defined structure which you must follow. In this case everything must be between the
<resources>
.... everything must be here ....
</resources>
tags. Putting anything after the </resources> will result in the 'not well formed error'. (The <?xml version="1.0" encoding="utf-8"?> is the exception and must be first).
Also some of your
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster"
values do not end properly. There must be a /> at the end of each item - like this:
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster" />
I want to support multiple languages in my app using sqlite database and xml resources.
For example, the user can insert transaction objects. Each transaction has a category.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="categories">
<item>#string/category1</item>
<item>#string/category2</item>
<item>#string/category3</item>
<item>#string/category4</item>
<item>#string/category5</item>
</array>
</resources>
What is the correct approach to use the above values in sqlite? Should a table be created or I can use them directly from xml?
If I want the user to be able to also add his own categories, how the multi-language thing should work?
Please read the two following google guides about supporting different languages and localizing:
http://developer.android.com/training/basics/supporting-devices/languages.html
http://developer.android.com/guide/topics/resources/localization.html
the normal way is to create a strings.xml for every language:
For Storing your categories in your SQLite Database you should enumerate your Categories and store only the numbers, so you are independent of the spelling. Adding a user defined Catergory should also work this way.
MyProject/
res/
values/
strings.xml
values-es/
strings.xml
/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Hello World!</string>
</resources>
/values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mi Aplicación</string>
<string name="hello_world">Hola Mundo!</string>
</resources>
I'm making an android app and since I've just started I want to try get the most organised code/resources. In my strings.xml file so far I have this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="stop">Stop</string>
<string name="start">Start</string>
<string name="preferences">Preferences</string>
<string name="back">Back</string>
</resources>
All of the strings except app_name are used in an options menu. But since I will be adding much more strings I was thinking that it might be better to do something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
Is it the best way or should I use another system?
It depends on where the strings will be used. If "stop" will never be used anywhere but in a menu, calling it "menu_stop" is a good idea. If it'll be used all over the place then it should just be called "stop".
Also, XML comments are very useful for organizing resources.
<resources>
<string name="app_name">GameController</string>
<!-- Menu Strings -->
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
Finally, if you find you have tons and tons of string resources you may want to go so far as to separate them into different xml files: menu_strings.xml, dialog_strings.xml, etc.
menu_strings.xml
<resources>
<!-- Menu Strings -->
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
dialog_strings.xml
<resources>
<string name="dialog_cancel_yes">Yes, cancel.</string>
<string name="dialog_cancel_no">No, do not cancel.</string>
</resources>
This is kind of a subjective question, really. You should use whatever you find easier to handle. I certainly do the second type of naming when I'm using layouts and drawables (e.g. button_x, ninepatch_x, icon_x, etc.), just because it keeps them next to each other, and is easier to narrow down quickly with Content Assist. In XML, you can use comments to group them together, and add white space, just anything that makes it easier for you to find what you need, and quickly.