将所有硬编码字符串提取到字符串资源 [英] Extract all hardcoded strings to string resource

查看:36
本文介绍了将所有硬编码字符串提取到字符串资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有 Alt + Enter 组合来提取单个字符串到字符串资源.但我想知道有什么可以将我的项目的所有字符串提取到字符串资源中的吗?

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?

如果我制作其中之一,Android 工作室也不会制作相同的字符串到字符串资源.

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

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

例如.我使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.

推荐答案

根据您的要求,据我所知,您真正要寻找的 android studio 中没有这样的功能,但这里有一些替代方法可以帮助您.

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.

  • 转到Analyze > Run Inspection ..",然后输入Hardcoded strings".在您的整个项目中运行它,您将获得一个检查结果面板,该面板将显示项目的所有硬编码文本.然后按 Alt + Enter,您将获得一个选项以自动提取该字符串.

  • 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.

这篇关于将所有硬编码字符串提取到字符串资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆