As a user of Android Studio, I'd like to know where a string in strings.xml is used because I want to remove the strings which aren't in use.
Right click on a string in your strings.xml-> click "Find Usages" to see where it's used.
If it's not used anywhere then a little dialog will pop up in the corner saying so.
Easier way to find unused strings in Strings.xml is to launch an inspection code from top menu of Android Studio (Analyse/Inspect code) on whole project.
In the inspection window, go to "Android Lint/Unused ressources", there you will find all the unused strings.
It will avoid you to make "find Usages" for lot of strings !
Related
I'm trying to translate a strings.xml file on Android Studio but it seems like the Translations Editor is not enabled (it does not appear as an option when I right click on the strings.xml file). I've tried deleting and installing back Android Studio but it's still the same; any ideas on how to solve?
Thank you in advance!
this is the "no enabled action found message I get
you have to open the string.xml file, then you will see the open editor option on the upper right side
Reopen the Android Studio IDE, it'll solve the problem. Also it will update the strings and refresh the layout of any layout xml.
Translations Editor shows up when you right-click on string resource files whose names end with strings.xml. On others it does not. The same goes for editor option that is supposed to show up in upper right side when string resource file is opened.
So, filenames like strings.xml, preferences_strings.xml, etc. are fine, while strings_intro.xml, etc. are not.
In case you don't have any string resource files named in that way, you can create an empty one named strings.xml and use it to open Translations Editor.
Or, you can open the it in the following way:
Open any xml layout file
Switch to 'Design' view in upper right corner
Design toolbar will look something like the following:
Click on the localizations option (globe icon)
At the bottom of the drop-down menu you will see 'Edit Translations...' option
Click on it - and there you are!
IntelliJ IDEA has an inspection that checks for spelling. In the analysis overview, I can see how many spelling mistakes were found, e.g. 12 typos found. In the code they are highlighted using a wavy green line.
However, I find it very hard to look manually for those wavy lines. Is there a keyboard shortcut or a search function which will automatically skip to the next highlighted typo?
F2 and Shift + F2 shortcuts will navigate you to the Next / Previous highlighted error. You need to configure the error navigation first to Go to next problem instead of default Go to high priority problems option(from the context menu of editor right side bar):
See help for details. Another option is to use double click (F4 shortcut) from the Inspection Results window to go to the source.
IntelliJ IDEA 2016.3
If you want to fix all typos from the project, you can list all of them and iterate through them using double click (or F4 to open the source):
Analyze > Run Inspection by Name...
Type "Typo"
You will be able to see a list containing all typos grouped by file:
In Settings -> Editor -> Colors & Fonts -> General, you can add an 'Error stripe mark' color to Typo.
With the default settings of IntelliJ I find it difficult to spot the typos. So I do the following hack to spot and correct them once in a while.
Temporarily change inspection setting to show Typos as Errors.
IntelliJ then highlights the typos as Errors, making it much easier to spot them in the editor. I correct them and then revert the inspection setting changes. The changes can be kept permanently but I don't prefer that!
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'm using Eclipse 3.7 (Indigo). I have some very long string item definitions/values - e.g. over 1000 characters with a lot of embedded XML segments. The copy function works in the strings.xml tab where the XML characters are replaced by their multi-character equivalents but not the Resources tab. Whenever I select the definition/value text - either by using the cursor or using the shift-arrow keys, I do not activate the 'copy' or 'cut' commands.
Does anyone have the secret?
At the beginning i use to do everything on the resource tab , BUT then i started to have some problems that when i pasted the info it was not showing there, but it was being pasted on the resource node for some reason, so it make it my XML invalid.So i better started to do it on the XML tab, cause is faster also. So when you need to do something fast and pretty, you better do it on the XML tab, is less buggy.
UPDATE:
If your problem is just that you want the text with the values like ''' decoded. then you can just copy the text from the XML tab and go to this site and entered there and click decode and you will get your decoded version of your text.
What version of Eclipse do you have? I know some versions have been buggy for keyboard mapping and shortcuts.
Try looking at how those shortcuts are defined. See column "When" in Preferences > General > Keys (image).
Check if those shortcuts do not work for any editor (do they work for Java editor?). If they work for some editors, and not for another, then the problem might be that a plugin setting is causing them to perform another command. You could try disabling all unnecessary plugins.
EDIT:
I also found a bug report on the Eclipse website that affected Eclipse 3.5. It looks like the fix was to go to Window > Preferences > Java > Editor > Typing, then uncheck "Update imports".
I've defined a template to use to help typing out XML string definitions, which I've given the name "astring". In Content Assist, I've turned off XML Tag Proposals:
But I still get these two extraneous options "string" and "comment" coming up as the top suggestions when I hit Ctrl+Space
Am I doing something wrong? Why does unchecking "XML Tag Proposals" and changing the order have no effect?
update:
1) It seems like the extra XML tag proposals only appear in the Android XML editor, not the "standard" one
2) However I get extra template proposals coming up in both editors, until I type some extra characters to narrow down the name.
I am not sure if this is a bug or by design. I think a bug, because I would expect it work like the Java completion whereby it takes into account the characters already typed, as soon as I press the completion key.
So a workaround for the normal XML editor is to press Ctrl+Space before starting to type the name of your template. But you still get the Tag Proposals in the Android XML editor.
Should I enter this as a bug in Eclipse or in the Android plug-in, or both?
Are there any default XML templates (XML / XML Files / Templates) that might be similar to the tag proposals?
You can also check Windows > Preferences > General > Editors > File Associations and switch to a different XML editor of your liking.
As a last resort, try changing the locale to English/US temporarily to avoid a known bug and restart Eclipse. Visit Control Panel; Region/Language, Administrative (or Advanced); Language for non-Unicode Programs; Change system locale.