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>
Related
I want to use a different string resource on small screens but Android always uses the default string. Am I doing it wrong?
/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="continue">Continue</string>
</resources>
/res/values-large/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="continue">Continue to Next Page</string>
</resources>
#string/continue always resolves to "Continue", even on large screens. It does, however use the dimensions in /res/values-large/dimens.xml so I'm sure I'm using the right resource qualifier. I also tried /res/values-w550dp/strings.xml and it didn't work either.
Am I doing something wrong or is this a limitation of Android?
values-large is only available for dimens and styles, but not for string resources.
one could possibly add custom string-arrays and then look them up accordingly.
see Android Resource Types.
On Android, I would like to suppress lint on a specific string value or specific line on a string.xml or other resources files.
<string name="suppress_lint_string">Suppress this String</string>
<string name="dont_suppress_lint_string">Don\'t Suppress this String</string>
I would like to perform specific lint suppressing on specific strings and specific parts of layouts for examples like missing translations for specific strings that doesn't really matter between languages.
If you want to suppress specific rules in specific strings without suppressing the whole file, you can use annotations.
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--suppress MissingTranslation -->
<string name="suppress_lint_string">ignore my translation</string>
...
</resources>
You can substitute MissingTranslation with any other lint rule.
http://tools.android.com/tips/lint/suppressing-lint-warnings
I am programming an application contains layouts with some views. I load these colors from values/colors.xml. Now, I want to define multiple themes for my application, e.g. Blue and Green (some sort of blue and green colors). My question is how can I define two colors.xml file and load it based on some conditions or choosing by user. What I want is some thing like strings.xml that we can load strings based on locale defined.
Thanks in advance.
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="white">#FFFFFF</string>
</resources>
values-fr/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="white">#EEEEEE</string>
</resources>
button.setBackgroundColor(Integer.parseInt(getString(R.string.white)));
Is there a way to add localization setting in my app? I'm going to add a preference/setting in my app and there is a localization option. So the user can change the language I have provided from the values string.
I was googling around but found nothing. Wondering you guys can help me, and give example or link to the tutorial.
You don't need to provide a setting for that, Android will do that for you. You just have to provide the translations for the languages you want to support.
You can do this for French for example by creating a folder named res/values-fr in your resources folder and putting your translations in there.
so in the res/values folder you would have a strings.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Map</string>
</resources>
and in the res/values-fr you woud have another string.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Carte</string>
</resources>
Your app will use the translation that best matches the language that the user has selected on their device.
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.