4

In Android Studio, Alt + Enter > "Extract String Resource" in a java file will open the following window:

enter image description here

Please note that the Resource name field is blank. However, the window will be like the following for a layout XML file: enter image description here

Please note the Resource name field is filled automatically.

How can the Resource name field be filled with an automatically generated name for java files too?

It thought the Resource name was filled automatically for all types of files before the current version of Android Studio (2.1), but I could be wrong.

[edit] 2018-05-29: I want to emphasize the question is about "automatically generated resource name", not about whether one can extract a hard-coded string. Extracting a hard-coded string from a java file has always been available, but the automatic name generation is not there.

Hong
  • 17,643
  • 21
  • 81
  • 142

2 Answers2

5

You can use this software to do this automatically https://www.jetbrains.com/help/idea/2016.2/recognizing-hard-coded-string-literals.html

I had a mistake with the link (thanks for giving me a bad reputation) , however this question is duplicated many times...

I hope this help you, and next time, think that we spend our time only for help other people. Good luck friend!

How can I find all RELEVANT hard coded strings in Android Studio?

Auto Generate @String reference in Android Studio

Android: resource String automatic generation

Possible to highlight hard-coded string literals and navigate between them?

How can I find all hard coded strings in my project in Android Studio

What is the short cut to extract strings from Android code into the strings.xml file in Intellij?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
garatu
  • 350
  • 3
  • 13
  • 1
    I do not know who down-voted your previous answer. I always appreciate any help even if it is not what I asked for like this one. I was asking specifically for a way to generate the name automatically when extracting a string. – Hong Aug 23 '16 at 22:08
2

Just making the answer from @garatu explicit here:

(crtl + alt + s) -> Editor -> Inspections -> Internationalization Issues -> Hard Coded Strings

enter image description here

Francislainy Campos
  • 3,462
  • 4
  • 33
  • 81