Sergey Shustikov
Sergey Shustikov

Reputation: 15821

Android find all hardcoded strings in code using Android Studio

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.

Upvotes: 20

Views: 15057

Answers (4)

TapanHP
TapanHP

Reputation: 6181

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

Upvotes: 3

Sergey Shustikov
Sergey Shustikov

Reputation: 15821

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.

Upvotes: 16

Ryan Amaral
Ryan Amaral

Reputation: 4279

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.

Upvotes: 74

PAD
PAD

Reputation: 2330

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.

Upvotes: 1

Related Questions