在哪里存储字符串值?在strings.xml中或常量类? [英] Where to store string values?In strings.xml or in constants class?

查看:183
本文介绍了在哪里存储字符串值?在strings.xml中或常量类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上,我们可以存储无论是在的strings.xml文件中或在一些常量类的静态最终variable.Is有某种原因,在某些情况下选择了另外一个?字符串值

In android, we can store string values either in strings.xml file or in some constants class as static final variable.Is there some reason for selecting one over another in some circumstances?

推荐答案

在一言以蔽之:

为code使用价值:使用常数总是class.Advantage:codeS始终融合和你的包可以在其他项目/环境中使用。你不能做到这一点与string.xml因为它不与你的包运输。

value for use in code: use always constants class.Advantage: codes remain integrated and your package can be utilized in other projects/contexts. You can not do that with string.xml as it is not transported with your package.

在UI显示的值:使用string.xml。优点:你可以用本地化显示翻译后的文本

value for display in UI: use string.xml. Advantage: you can use localization to display translated texts.

当两个选项似乎可行可能出现的一些情况。你必须再决定在哪里存储其相关的值。

Some situation may arise when both option appears viable. You will have to then decide where are its related values are stored.

这篇关于在哪里存储字符串值?在strings.xml中或常量类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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