Auto Generate @String reference in Android Studio

AndroidIntellij IdeaAndroid Studio

Android Problem Overview


I know that this is possible in eclipse by following the advice here: https://stackoverflow.com/questions/12219299/android-resource-string-automatic-generation

But I can't seem to find if this is possible in android studio yet. Anybody know how to do this?

Basically I would like to take a hardcoded string and auto create a @string reference in my main values.xml or strings.xml.

Android Solutions


Solution 1 - Android

Alt+Enter, Extract String Resource while the caret is inside the hardcoded string:

extract

The same should work in XML files as well, and it does work in IntelliJ IDEA, but seems to be broken in the current version of the Android Studio:

XML extract resource

Android Studio 0.1.3 shows the folded text in XML layouts that it extracts from the string resources, but it fails to navigate back to the resource and doesn't offer to extract resources from the hardcoded strings inside XML. It appears to be a bug.

Solution 2 - Android

What seems to be missing from the above answers is that, in Android Studio, you must place the cursor in the string, click the mouse, and press Alt + Enter to bring up the Extract String Resource dialog

Solution 3 - Android

alt+Enter work when your setting string resource is on,

how to on string resource extractor

>Goto Android studio 'Help' -> Find action -> type "extract string resource"

You will find a ON / OFF button. Switch on the option.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionb1kjshView Question on Stackoverflow
Solution 1 - AndroidCrazyCoderView Answer on Stackoverflow
Solution 2 - AndroidMickView Answer on Stackoverflow
Solution 3 - AndroidYogesh RathiView Answer on Stackoverflow