Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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
Android 从xml设置字符串时读取字符串目录不正确_Android - Fatal编程技术网

Android 从xml设置字符串时读取字符串目录不正确

Android 从xml设置字符串时读取字符串目录不正确,android,Android,我更改了默认的本地语言,但在android 7中,在将配置再次更改为横向和纵向之后,打开了在xml布局中设置的页面字符串,从默认目录中读取字符串 java android:text=“@string/test” 此字符串不显示-->سلام;将显示-->测试; 但如果我在java中以编程方式设置字符串,这将起作用,文本为-->سلام java setText(G.context.getResources().getString(R.string.test)); 我还检查每个更改配置中的本地

我更改了默认的本地语言,但在android 7中,在将配置再次更改为横向和纵向之后,打开了在xml布局中设置的页面字符串,从默认目录中读取字符串

java
android:text=“@string/test”

此字符串不显示-->سلام;将显示-->测试; 但如果我在java中以编程方式设置字符串,这将起作用,文本为-->سلام

java
setText(G.context.getResources().getString(R.string.test));

我还检查每个更改配置中的本地语言

```爪哇

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    G.handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            checkLanguage();
        }
    }, 200);
}

public static void checkLanguage() {

    try {
        String selectedLanguage = G.selectedLanguage;
        if (selectedLanguage == null) return;
        Locale locale = new Locale(selectedLanguage);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        G.context.getResources().updateConfiguration(config, G.context.getResources().getDisplayMetrics());
        // }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

```

当您将配置更改为横向时,您应该有另一个同名的版面,用于该版面并在其中放置相同的文本。

当您将配置更改为横向时,您应该有另一个同名的版面,用于该版面并在其中放置相同的文本

惊人的解决方案

在下面的代码行中,我使用了全局上下文

 G.context.getResources().updateConfiguration(config, G.context.getResources().getDisplayMetrics());
在这之后,将旋转改为横向,再次改为纵向,xml布局中使用的@string/test没有正确工作,显示了'test',而不是显示波斯语单词'

但现在

我刚刚删除了填充应用程序的全局上下文

 getResources().updateConfiguration(config, getResources().getDisplayMetrics());
这个问题终于解决了:)

惊人的解决方案

在下面的代码行中,我使用了全局上下文

 G.context.getResources().updateConfiguration(config, G.context.getResources().getDisplayMetrics());
在这之后,将旋转改为横向,再次改为纵向,xml布局中使用的@string/test没有正确工作,显示了'test',而不是显示波斯语单词'

但现在

我刚刚删除了填充应用程序的全局上下文

 getResources().updateConfiguration(config, getResources().getDisplayMetrics());

最后,这个问题解决了:)

我有一个xml布局,不需要使用另一个xml,而且这个问题只是当我从android 7使用时,我有一个xml布局,不需要使用另一个xml,而且这个问题是当我从android 7使用时