新的Android API 22 getResources().getDrawable()现已弃用.现在最好的方法是只使用getDrawable().
改变了什么?
android android-resources android-drawable android-5.1.1-lollipop
我将项目相关图像存储在drawable文件夹中.另外,我将图像名称存储在字符串变量中,并且我正在尝试将这些图像设置为imageview.但图像没有显示.请帮助我这方面.
我的代码:
int res = getResources().getIdentifier(imagename, "drawable", this.getPackageName());
imageview= (ImageView)findViewById(R.id.imageView);
imageview.setImageResource(res);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,"imagename"是包含图像名称的字符串变量.
提前致谢
我知道如何从res/drawable中设置图像/图标
<ImageView android:id="@+id/ImageSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android_green_3d"/>
Run Code Online (Sandbox Code Playgroud)
如果我们直接从代码中设置它:imageView1.setImageResource(R.drawable.android_green_3d);
但我们也可以从android.R.drawable中获取图标,如下所示:imageView1.setImageResource(android.R.drawable.ic_menu_more);
如何在xml id中设置图像/图标源是android.R.drawable?谁知道?提前致谢.