我很初学java,请帮忙。我有一个Android应用程序源代码。我默认ImageView的是这样的:Android:如何从字符串设置ImageView src?
<ImageView
android:id="@+id/flag_logo"
android:layout_marginBottom="@dimen/global_keyline_s"
android:scaleType="fitCenter"
android:src="@drawable/flag_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cropToPadding="false"
android:adjustViewBounds="true" />
我需要我的应用程序在某些国家的翻译,我需要动态设置应用程序标题和标志图标。
我有字符串资源,并已翻译:
<resources>
<string name="app_name">My App Name</string>
<string name="flag_icon">@drawable/flag_icon</string>
...
</resources>
在ImageVeiw,我可以改变:
android:src="@drawable/flag_icon"
到android:src="@string/flag_icon"
?
当我测试这个脚本模拟器它是好的,但是当我尝试生成到签署的apk我得到错误:
Error:(4) Error: Unexpected resource reference type; expected value of type @string/ [ReferenceType]
我一直在寻找这个问题,但还没有找到,请帮忙。谢谢。
我有个问题。为什么? – Blackbelt
您无法将imageview src更改为字符串src。 Imageview src不过是图像文件。 – Shriram
android:src =“@ drawable/flag_icon”是一个整数值,并且您正在调用一个字符串值,问题是为什么? –