-1

为了更好地解释:例如,我有两种语言可用。这就是为什么我会有英语图像和俄语图像。我在一个可绘制的 xml 文件中引用了它们。

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/image_eng"></item>
<item android:drawable="@drawable/image_ru"></item>

</selector>

我应该使用什么类型的可绘制 xml 文件?如何设置和检测状态并切换图像?基本上它就像android:state_

4

2 回答 2

2

If I understand correctly, you want to use one image when the phone is in English, and the other when the phone is in Russian. You should use the language modifiers on the drawable folder, not in the drawable name.

So, you would have a folder named drawable-en, which would contain your image for English (drawable-en/image.png, for example). Then, have another folder named drawable-ru which contains your Russian version of the image, but it must have the same name (drawable-ru/image.png).

Then, in your layout XML (or wherever you're referencing the drawable) just reference @drawable/image ... Android will automatically choose the appropriate image.

于 2013-02-06T18:08:56.760 回答
1

请阅读Android 资源本地化的工作原理。

您不必为此使用选择器,也不必强制执行任何操作。

只需将您的图像文件放在以下文件夹中:

  • res/drawable-en
  • res/drawable-ru

在您的代码中,您可以使用:

Drawable draw = getResources().getDrawable(R.drawable.image);

该应用程序将根据手机的语言选择合适的

于 2013-02-06T18:12:02.043 回答