52

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.

Community
  • 1
  • 1
b1kjsh
  • 1,109
  • 2
  • 9
  • 21

3 Answers3

122

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    So it's like the CTRL+1 for eclipse ? wonder why all of the key combinations have changed. maybe because it's a different IDE... – android developer Jun 08 '13 at 09:54
  • 1
    @CrazyCoder is there a way to reset the options of the new IDE to work like on eclipse ? it's quite annoying to get used to totally different keys. let alone if i've changed eclipse's options... maybe there is a way to import the settings from eclipse? – android developer Jun 08 '13 at 10:23
  • 3
    It's a completely different IDE with its own set of options. There is Eclipse keymap that you can [enable in Settings | Keymap](http://img560.imageshack.us/img560/8154/20130608142429.png), but some other options may not transfer. If you are familiar with Eclipse and happy with it, you probably don't need Android Studio. – CrazyCoder Jun 08 '13 at 10:25
  • @CrazyCoder but i've noticed that it has some really cool features as shown in the google io event. sadly i don't think google will add all of those features into eclipse. choice is good, but this time i really don't know what to do. i really like features, but i'm much more familiar with eclipse. – android developer Jun 08 '13 at 10:28
  • 1
    Working in Android Studio version AI-130.737825 – Ilari Kajaste Sep 17 '13 at 07:23
  • is it possible to have shortcut without dialog pop up? – Mladen Rakonjac Jul 27 '16 at 19:04
  • I knew there had to be an easy way! :) – Inoy Aug 11 '16 at 09:42
21

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

mmBs
  • 8,421
  • 6
  • 38
  • 46
Mick
  • 663
  • 1
  • 9
  • 18
  • 2
    Alt + Enter does not bring up an extract resource dialog in 2.2.3. Does anyone know how to do it there? – Eddy Jan 19 '17 at 18:51
3

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.

Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81