Android 我们应该在Strings.xml还是在layput xml文件本身中给出字符串值

Android 我们应该在Strings.xml还是在layput xml文件本身中给出字符串值,android,android-layout,Android,Android Layout,我有一个问题是,在strings.xml文件中给出布局文件中要使用的所有字符串文本是好的,还是应该在布局文件本身的“字符串文本”中给出属性值,如android:text=“some text” 我们应该在strings.xml中指定所有字符串文本,或者只指定特定的字符串。如果您决定将应用程序国际化,您最好将所有字符串提取到strings.xml!然后,您只需为每种语言执行不同的strings.xml,而不必进行布局 在查看了的源代码和其他一些类之后,很明显使用资源和通过getResources(

我有一个问题是,在strings.xml文件中给出布局文件中要使用的所有字符串文本是好的,还是应该在布局文件本身的“字符串文本”中给出属性值,如
android:text=“some text”


我们应该在strings.xml中指定所有字符串文本,或者只指定特定的字符串。

如果您决定将应用程序国际化,您最好将所有字符串提取到strings.xml!然后,您只需为每种语言执行不同的strings.xml,而不必进行布局

在查看了的源代码和其他一些类之后,很明显使用资源和通过
getResources()
获取资源的成本有点高

然而,使用getResources()有其优点

  • 它帮助你将你的资源外部化
对于任何类型的资源,您都可以指定默认资源和多个备选资源,具体取决于区域设置、屏幕深度/分辨率



在这两种情况下,你都可以编写代码,你是如何做到的!!??
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:id="@+id/ll1"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

    <Button android:text="Button" 
    android:id="@+id/butShow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </Button>


</LinearLayout>
<resources>
    <string name="btnLabel">Button</string>
</resources>