Extract all hardcoded strings to string resource

前端 未结 4 2207
温柔的废话
温柔的废话 2020-12-05 15:15

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

相关标签:
4条回答
  • 2020-12-05 15:37

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

    0 讨论(0)
  • 2020-12-05 15:38

    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.

    0 讨论(0)
  • 2020-12-05 15:39

    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.

    0 讨论(0)
  • 2020-12-05 15:43

    For hardcoded strings in XML layout files:

    Click on Analyze -> Run inspection by name -> enter Hardcoded strings -> select the whole project -> OK. Here, you will get all the hardcoded strings from your xml layout files only that u can extract to strings.xml by:

    Click on the hardcoded text -> Alt + Enter -> extract from resource -> enter your corresponding resource name for that string -> OK

    For hardcoded strings in Java class code:

    Click on Analyze -> Run inspection by name -> enter Hardcoded texts -> select the whole project -> OK. Here, you will get all the hardcoded strings from your Java class files only that u can extract to strings.xml by:

    Click on the hardcoded text -> Alt + Enter -> extract from resource -> enter your corresponding resource name for that string -> OK -> add getString for each string resource created in your java code.

    Hence, Hardcoded strings -> Java class code whereas Hardcoded texts -> Xml layout files in Android Studio.

    0 讨论(0)
提交回复
热议问题