的getString()和getResources.getString之间差()getString、getResources

2023-09-12 09:32:37 作者:跪下、叫帅哥

我注意到活动类有两个不同的方法来得到一个字符串资源。 这可以通过使用

I noticed that the Activity class has two different methods to get a String resource. This is possible by using:

的getString(INT渣油):返回一个本地化的字符串从应用程序的包的默认字符串表

getString(int resId): Return a localized string from the application's package's default string table.

getResources()的getString(INT ID):返回与特定的资源ID关联的字符串值。任何样式的文本信息将被剥离。

getResources().getString(int id): Returns the string value associated with a particular resource ID. It will be stripped of any styled text information.

我不明白什么是两种方法之间的差异。谁能告诉我?

I don't understand what's the difference between both methods. Can somebody tell me?

推荐答案

他们是一样的Activity.getString(int)正是这么做的:

They are the same as Activity.getString(int) does exactly that:

 public final String getString(int resId) {
     return getResources().getString(resId);
 }
 
精彩推荐
图片推荐