Android find all hardcoded strings in code using A

2020-02-10 12:52发布

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.

标签: android
4条回答
混吃等死
2楼-- · 2020-02-10 13:08

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.

查看更多
疯言疯语
3楼-- · 2020-02-10 13:13

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.

查看更多
闹够了就滚
4楼-- · 2020-02-10 13:26

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

查看更多
▲ chillily
5楼-- · 2020-02-10 13:27

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.

查看更多
登录 后发表回答