Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自xml的Android本地化字符串_Android_Xml_Android Resources - Fatal编程技术网

来自xml的Android本地化字符串

来自xml的Android本地化字符串,android,xml,android-resources,Android,Xml,Android Resources,我的res文件夹中有xml文件夹,文件结构如下: <questions> <question number="1" text="my string" numberTwo="1" /> ... </questions/ ... 你可以 xml文件中的text=“mystring” 和lalala在您的strings.xml中(可能在其他文件中

我的
res
文件夹中有
xml
文件夹,文件结构如下:

    <questions>
        <question
            number="1"
            text="my string" 
            numberTwo="1" />
         ...
    </questions/

...
你可以

xml文件中的
text=“mystring”

lalala
在您的strings.xml中(可能在其他文件中本地化,例如在文件夹values-de.xml中)

然后在代码中可以执行以下操作:

int stringId = getResources().getIdentifier("mystring", "string");
String string = getString(stringId); // that will be "lalala"

另一种方法是将xml文件完全本地化到文件夹xml de中,但这会导致一些文本重复。

in string.xml->lalala in your strings.xml ->文件夹值-de.xml 然后在代码中,您可以在活动中执行以下操作:

String AppName=getResources().getString(R.string.app_name);
在弗拉格梅顿

String AppName=getActivity().getResources().getString(R.string.app_name);