How to access the resource of COM.ANDROID.INTERNAL.R

Source: Internet
Author: User

Recently working on an Android player project, you want to use Android's internal resources by default, such as:

Com.android.internal.r.layout.media_controller



However, direct use will report a compilation error:

com.android . internal . r does not exist

You cannot import the internal Android class, as the internal. R class isn ' t visible.

However, it can be accessed in other ways, as follows:

int mediacontrollerid = Resources.getsystem (). Getidentifier ("Media_controller", "Layout", "Android"); View layout = ((layoutinflater) Mcontext.getsystemservice (Context.layout_inflater_service)). Inflate ( Mediacontrollerid, this);



Similarly, you can access:

Mprevbutton = (ImageButton) Layout.findviewbyid (Resources.getsystem (). Getidentifier ("prev", "id", "Android")); Mprogress = (ProgressBar) Layout.findviewbyid (Resources.getsystem (). Getidentifier ("Mediacontroller_progress", "id" , "Android")), Mpausebutton = (ImageButton) Layout.findviewbyid (Resources.getsystem (). Getidentifier ("pause", "id", " Android "));

The getidentifier is used as follows, which returns the ID of the name corresponding to the

Resources.getsystem (). Getidentifier (name, Deftype, Defpackage)



And how did the above Name/deftype/defpackage get? can obtain the corresponding information from the source code http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/ Android/widget/mediacontroller.java

How to access the resource of COM.ANDROID.INTERNAL.R

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.