Android 如何以编程方式引用所需的值文件夹?

Android 如何以编程方式引用所需的值文件夹?,android,locale,Android,Locale,我知道android会根据区域设置选择适当的values文件夹。但我想自己从代码中选择它 <com.example.typefacetest.CustomTextView android:id="@+id/banglaTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" custom:banglaText="@s

我知道android会根据区域设置选择适当的values文件夹。但我想自己从代码中选择它

 <com.example.typefacetest.CustomTextView
        android:id="@+id/banglaTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:banglaText="@string/hello_world"
        android:text="@string/hello_world"
         />

在我的
values bn
文件夹中,我有一个名为
hello\u world
的字符串literal,用于属性
custom:banglaText
。如果我不设置区域设置,android将不会选择
values bn
文件夹。现在我想以编程方式从该文件夹中提取字符串。如何做到这一点?

你可以用这个:或者写这样的东西:

Configuration configuration = getResources().getConfiguration();
configuration.locale = new Locale("en");
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, configuration);
String string = resources.getString(id);

在id中,您应该从strings.xml中输入字符串的id。

我不想设置configuration.locale,因为不建议这样做。