Android uses Getidentifier () to get the resource ID

Source: Internet
Author: User

Mainly by two methods:

1, do not put the picture under the res/drawable, but stored in the SRC package (such as: Com.drawable.resource), in this case, the method of invocation is:

String Path = "Com/drawable/resource/imagename.png"; InputStream is = getClassLoader (). getResourceAsStream (Path);D Rawable.createfromstream (IS, "src");

2, if you still want to directly use the res/drawable in the picture, [ Assuming the creation of the project, fill in the package name: Com.test.image] need to pass the following method:
int resID = Getresources (). Getidentifier ("ImageName", "drawable", "Com.test.image");D rawable image = Getresources (). Getdrawable (ResID);



Android uses Getidentifier () to get the resource ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.