android-studio - "Instead of hardcoding strings in the layout, it' 是使用字符串资源的最佳实践。”但是为什么呢?

标签 android-studio

<分区>

我是 Android Studio 的新手,我只是想知道为什么最好使用字符串资源而不是在布局中硬编码字符串。 能否请您尝试用不太技术性的人类友好语言向我解释这一点。

最佳答案

当您想要更改字符串的内容时,在 strings.xml 中查找相同的内容并在那里进行更改会更容易,它会反射(reflect)您使用它的所有地方。

如果你在多个文件中使用相同的字符串常量,你可以只在一个地方改变它而不是在多个文件中改变它,

它还可以防止拼写错误和错误,还可以增加代码的可读性

关于android-studio - "Instead of hardcoding strings in the layout, it' 是使用字符串资源的最佳实践。”但是为什么呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56919745/

相关文章:

android - ProGuard 无法删除 Log.i 函数调用

java - 构建应用程序时出错无法删除/output.json?

android - 为使用 ViewPagerIndicator 的 Android 项目创建 Gradle 构建

android - 使用 0.4.3 Android Studio,错误 : "Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly"

java - 静态上下文警告

android-studio - Toast错误 "None of the following functions can be called with the arguments supplied:"

android - 无法在任务 'jniFolders' 上设置只读属性 ':android:packageDebug' 的值

java - Android Studio、Java 8 和函数

android-studio - 修改后需要CLEAN PROJECT的未知错误

android-studio - Android Studio : Unable to open connection to: localhost/127. 0.0.7 :5037, 由于 : java.net.ConnectException:连接被拒绝