Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Generate @String reference in Android Studio

I know that this is possible in eclipse by following the advice here: 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.

like image 555
b1kjsh Avatar asked Jun 07 '13 05:06

b1kjsh


2 Answers

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.

like image 76
CrazyCoder Avatar answered Oct 04 '22 17:10

CrazyCoder


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

like image 36
Mick Avatar answered Oct 04 '22 18:10

Mick