I've tried to create my own string resource 'click_me' using values > strings.xml and then using the Resources tab to add Strings. I created a few too many but I'm unable to delete the extra Strings. When I click on remove the extra Strings are not removed from the resources tab.
Yet when I switch to the strings.xml tab only the default strings remain. I would like the Resources and strings.xml tabs to sync as I'm sure they're probably meant to. What's gone wrong here?
I tried it too and the problem is same here too. There seems to be a known issue and is posted here. I suppose its only logical to edit string resource directly in xml until the issue is fixed. My Adt version and relevant information:
Android Developer Tools
Build: v22.6.2-1085508
Blockquote
Related
I'm not sure if my question is worded correctly, but it's easier to show an image to explain my question.
In the XML editor, some values are replaced with the actual values that was defined for that entry. However, I don't want Android Studio showing me the actual values. Instead, I still prefer that it showed the reference names. So, how do you disable the editor from previewing in this manner?
In the image below, android:text="#string/sign_up", but the editor is showing it as android:text="Sign up...", as well as other attributes, and the reference name only shows up when I mouseover the attribute.
How to disable this feature permanently via Android Studio setting/configuration?
Update: Same thing is happening in .java files. Enums or R.string constants are being replaced by their actual values.
For Java files you can go to Preferences->Editor->General->Code Folding and uncheck "Android string references" but this only applies to code not to xml layouts
– Oleg Bogdanov
I fought with this for hours! Having the values show up instead of the references is great, in most cases, but I was working with a project imported from AIDE and its layouts were a mess. I need to see the references, not the values. I found the "possible duplicate" link above, mentioned by zombie, but it didn't work (or so I thought).
Finally, after reading this post, I tried unchecking the "Android string references" again, but this time I restarted Studio after (even though I wasn't prompted). If you have the same problem, the solution above should work, but save yourself (possibly) hours of aggravation and:
Restart Studio after unchecking the "Android string references" setting!
BTW, I would have added this as a simple comment, but SO wouldn't let me!
I am working on a new Android application with a navigation with the fixed tabs and scroll-able default option Eclipse gives you.
But when looking on my .xml files for the mainActivity and the dummy file that are generated automatically, I can't find out where to edit the titles and whatnot for each individual tab section.
Do you know what I need to do?
You can change the default value of tabs by changing res/values/string.xml>title_section(x). Note: using resource string files should be something you get very familiar with as you should try your best to separate any "magic strings" from your code. Basically all strings should go in a resource file and be referenced through getString.
I am working on a simple android application in eclipse IDE and I got a little yellow icon on the left hand side of a line of xml code that looks like a light bulb with an exclamation mark beside it. When I hovered over, it says "[I18N] Hardcoded string "input..., should use #string resource input". The running and debug was successful but I just want to get rid of it as I find it annoying. What should I do?
If it's annoying, there is a reason. You totally should use #string resources instead of your hardcoded strings. All you have to do is to put your string in res/values/strings.xml and reference it in your layout via #string/my_string_id_here.
This is extremely useful for multi language support, or for plurals strings.
You can learn more here.
Hope this will help you.
The right way:
Move all your strings into resource files, as suggested, and reference them in your views like so: #string/mystringname
The "other" way:
Turn off Lint warnings in Eclipse in Window/Preferences/Android/Lint Error Checking
Both ways will remove that annoying triangle :)
This warning is there because hardcoding strings into the android app's Java source code is not recommended. It will compile fine - but Android Lint will complain about it, so that's why it's a "warning" and not an "error". Generally, it is preferable to define them in the separate "string.xml" file.
If you want to know why, check this answer.
For an example, check this answer.
You should also take a look at the official documentation for string resources.
I am working on an app built upon an example from a tutorial. Now the different widget IDs no longer reflect their purpose so I would like to rename them. However, this seems quite a task as the IDs are used in multiple files.
Is it possible somehow to rename the IDs so the changes are migrated into the other files in the project? That is pretty much similar to refactor source code names, but for widget IDs.
I don't think a tool like that exists in Eclipse. The easiest way to do it manually is to rename an item in the XML layout and then track down the errors in the Java classes. If you do it one-by-one then you should have it cleaned up in a minute or two.
You can try to use the Find/Replace function is Eclipse. I have found this useful several times when changing ID's or something to that effect. Let us know what you end up doing.
In eclipse:
Go to the xml layout -> Graphical Layout -> Properties then click the ... button near the desired field:
In case anyone stumbles across this problem now, you can rename the ID from the visual layout editor and it will do all the hard work automatically.
I have a current Android app that uses i18n via resources. res/values-es/strings.xml and so on. When I test it on a device with the language set to Espanol it pulls the correct resources, from the values-es file, but the accent characters are way out of whack.
For example, I want to use the lowercase o with an accent (ó). I have tried with the actual character in the strings.xml file (using the character map on Ubuntu to create the string) and with the entity, in either case it comes out like some other character set accent I don't recognize:
The same character looks perfect WITHIN strings.xml when using many different text editors. And the file is UTF-8 (tried recreating it with the Android "wizard" tool in Eclipse to make sure).
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version">Versión</string>
</resources>
Now I've used French, and German before in other Android apps, with all sorts of accents, and haven't seen this problem, so I'm entirely confused at the moment. What am I doing wrong this time?
I finally solved this one. I was using a font and calling setTypeface earlier in the code. The font I'm using must not have the special characters needed for the other languages. I need to check to make sure my user's are using a locale that my font supports before setting the font.
I should have realized this and checked it earlier.
So the bottom line is this, if you get strange results with certain characters in different locales, make sure you're not using fonts that don't support those characters. Fall back to not using a font (don't call setTypeface) and test that way.
That diacritic is actually called a breve, common in many eastern european languages. I had the same problems before once. I even have a question here on SO. Since nobody solved the problem, it's worth the shot...
This isn't clear to me yet:
Does it happen only on this project? Did you try others? (maybe a project mistake)
Try including other language folders (try, say, values-fr). Do you have the same problem?
Did you try to build your app inside Eclipse? Did you try building manually on the command line?
Then, you could try:
Instead of the "ó" (here in PT we use the same), try \u00f3. Like: Versi\u00f3n. Do you get the proper latin small o with acute? Just to clear things.
Build your app using ant ($ ant release) manually on the command line. Report back the results.
This may help the guys here (who are much more experienced than I am) guess where the problem can be.
Best regards!
Check how the actual strings.xml file is stored.
In the file tree in Eclipse, right-click on the strings.xml file and select properties.
You will get a properties dialog for the file.
If not selected already, select the "Resource" line in the left column.
Check the "Text file encoding" area at the bottom.
It maybe selected as "default" or a specific encoding such as "UTF-8" selected.
Select the UTF-8 option. Save file. Clean & Build project (to re-gen resources) and then see if any changes.
See attached screenshot.
Suerte, Andrew
This is strange as it should not cause a problem. Maybe you should try to embed string into CDATA section, like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version"><![CDATA[Versión]]></string>
</resources>