Extract all hardcoded strings to string resource

若如初见. 提交于 2019-11-27 02:19:01

问题


I know there is Alt + Enter combination to extract single String to string resource. But I am wondering is there anything that I can extract all string of my project into string resource?

Also Android studio not making same String to string resource if I make one of them.

String s = "Hello World";
String s2 = "Hello World";

For example. I make "Hello World" to string resource still another remain Hardcoded in same file as well in the project too.

String s = getString(R.string.helloworld);
String s2 = "Hello World";

If anyone know something like that.


回答1:


As your requirements and as I know there is no such feature in android studio you were really searching for, But here are some alternative ways that can help you.

  • Go to "Analyze > Run Inspection ..", and type "Hardcoded strings". Run that in your whole project, and you will get an inspection results panel that will show all the hardcoded text of projects. Then hit Alt + Enter and you'll get an option to automatically extract that Strings.

  • Another approach is to Find and Replace But It's not better because of time consumption. To simplify the approach you can have a look at here for flexibility.




回答2:


In Android 3.2.1 you can go to Edit->Find->Find In Path... and then search for android:text=" . This will give you a list of all the hardcoded strings in xml files.

Search for Toast.makeText to find all the toast items from the java files.

Search for setText(" to search for text sets in java files and so forth.

You can do searches like this for items you would like to find throughout the project and replace.




回答3:


I believe the shortcut you are looking for is (on a Mac) Alt + Command + C



来源:https://stackoverflow.com/questions/35569783/extract-all-hardcoded-strings-to-string-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!