Is there a way to extract a string with an automatically generated resource name for a java file in Android Studio?

无人久伴 提交于 2019-12-08 07:10:40

问题


In Android Studio, Alt + Enter > "Extract String Resource" in a java file will open the following window:

Please note that the Resource name field is blank. However, the window will be like the following for a layout XML file:

Please note the Resource name field is filled automatically.

How can the Resource name field be filled with an automatically generated name for java files too?

It thought the Resource name was filled automatically for all types of files before the current version of Android Studio (2.1), but I could be wrong.

[edit] 2018-05-29: I want to emphasize the question is about "automatically generated resource name", not about whether one can extract a hard-coded string. Extracting a hard-coded string from a java file has always been available, but the automatic name generation is not there.


回答1:


You can use this software to do this automatically https://www.jetbrains.com/help/idea/2016.2/recognizing-hard-coded-string-literals.html

I had a mistake with the link (thanks for giving me a bad reputation) , however this question is duplicated many times...

I hope this help you, and next time, think that we spend our time only for help other people. Good luck friend!

How can I find all RELEVANT hard coded strings in Android Studio?

Auto Generate @String reference in Android Studio

Android: resource String automatic generation

Possible to highlight hard-coded string literals and navigate between them?

How can I find all hard coded strings in my project in Android Studio

What is the short cut to extract strings from Android code into the strings.xml file in Intellij?




回答2:


Just making the answer from @garatu explicit here:

(crtl + alt + s) -> Editor -> Inspections -> Internationalization Issues -> Hard Coded Strings



来源:https://stackoverflow.com/questions/36938055/is-there-a-way-to-extract-a-string-with-an-automatically-generated-resource-name

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