Android工作室;通过 url 在 drawable 中获取图像
Android Studio; get image in drawable through url
我想在 运行 时间内通过 url 在 android 工作室拍摄照片..
例如在eclipse中以这种方式通过url找到图像..
在这种情况下,eclipse 已经提供了该代码。我在 imagename 中传递图像名称,然后在 drawable 中获取图像。
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
如何在 android studio 中找到那个案例.. android studio 不接受此代码。如何在 运行 时间内找到图像
Java就是Java..用AndroidStudio或者Eclipse编译都无所谓。在你的情况下,我认为你有 getResource.getIdentifier
但你应该使用 getResources().getIdentifier(...)
试试这个代码:
检查 getIdentifier(...)
方法签名。
String uri="@drawable/" + imageName;
ivImage.setImageResource(getResources().getIdentifier(uri, null, getPackageName()));
这项工作很完美,但是当您调用 drawable
image 时,您确认包名称应该是正确的。它工作完美。
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
我想在 运行 时间内通过 url 在 android 工作室拍摄照片..
例如在eclipse中以这种方式通过url找到图像..
在这种情况下,eclipse 已经提供了该代码。我在 imagename 中传递图像名称,然后在 drawable 中获取图像。
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
如何在 android studio 中找到那个案例.. android studio 不接受此代码。如何在 运行 时间内找到图像
Java就是Java..用AndroidStudio或者Eclipse编译都无所谓。在你的情况下,我认为你有 getResource.getIdentifier
但你应该使用 getResources().getIdentifier(...)
试试这个代码:
检查 getIdentifier(...)
方法签名。
String uri="@drawable/" + imageName;
ivImage.setImageResource(getResources().getIdentifier(uri, null, getPackageName()));
这项工作很完美,但是当您调用 drawable
image 时,您确认包名称应该是正确的。它工作完美。
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));