Android find all hardcoded strings in code using Android Studio

前端 未结 4 476
轮回少年
轮回少年 2020-12-16 13:24

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

Toast.ma         


        
相关标签:
4条回答
  • 2020-12-16 13:50

    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.

    0 讨论(0)
  • 2020-12-16 13:56

    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.

    0 讨论(0)
  • 2020-12-16 13:57

    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

    0 讨论(0)
  • 2020-12-16 14:00

    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.

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