20

I want to find all hard-coded strings in my code to move them into strings.xml file for future localization. Such as :

Toast.makeText(context,"Hardcoded text",LENGTH_SHORT).show();

I using Android Studio.

Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119

4 Answers4

72

Go to Analyze > Run Inspection By Name... (Ctrl+Alt+Shift+I)

and type:

  • Hardcoded Text to find the hardcoded strings in the .xml files;
  • Hardcoded Strings to find the hardcoded strings in the .java files.

Run it against the whole project, and you should get an inspection results panel that will show the hardcoded text instances.

Ryan Amaral
  • 4,059
  • 1
  • 41
  • 39
16

This answer hasn't getting to me any result.

Nonetheless, for future searches :

In Android Studio 1.2.2 added new Option Hardcoded strings(not a Hardcoded text) and this getting to me perfect searches result.

Community
  • 1
  • 1
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
4

After android studio 1.2.2 It seems pretty easy way to do it,

Go to Analyze

Run Inspection by name

Type : HardCoded Text

And then by selecting appropriate module's option you can get all hard coded Strings in your whole project.

Tip : Short key : Ctrl + Alt + Shift + I

TapanHP
  • 5,969
  • 6
  • 37
  • 66
1

It seems it has been already answered here, isn't it relevant for your problem ? Edit : just don't forget to check "File mask(s)" box in the window after having typed "Hardcoded text", and select *.java, if you want to search in Java files.

And after you found all your hardcoded strings, this may help you to transfer them to XML.

Community
  • 1
  • 1
PAD
  • 2,240
  • 1
  • 22
  • 28