How Android references resources under the COM.ANDROID.INTERNAL.R directory

Source: Internet
Author: User

How Android references resource project requirements under the COM.ANDROID.INTERNAL.R directory

One resource is the same as a resource on the system, and you want to reference it: Frameworks/base/core/res/res/drawable/ic_text_dot.xml

File name: Ic_text_dot.xml

Specific content of the document:
<?xml version= "1.0" encoding= "Utf-8"?><!--Copyright (C) The Android Open Source Project Licensed under     The Apache License, Version 2.0 (the "License");     You are not a use of this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by Applica BLE law or agreed-in-writing, software distributed under the License is distributed on a "as is" BASIS, Withou     T warranties or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><inset xmln S:android= "Http://schemas.android.com/apk/res/android" android:inset= "10DP" > <shape android:shape= "Oval" > <solid android:color= "? android:attr/textcolorsecondary"/> <size android:width= "4DP" android:h eight= "4DP"/> </shape></inset>
The resource's reference in the code is: Com.android.internal.r.drawable.ic_text_dot encountered problems

But I do not know why, when I use Java code in the project to invoke this resource, has been prompted to fail, unable to find the target:

        ImageView ImageView = (ImageView) Findviewbyid (r.id.img);        Imageview.setimagedrawable (Getdrawable (Com.android.internal.r.drawable.ic_text_dot));          COM.ANDROID.INTERNAL.R cannot is resolved to a variable
Why the problem occurred

You cannot access ID ' s of COM.ANDROID.INTERNAL.R at compile time, but can access the defined internal resources at run Time and get the resource by name.

The solution is to:
        ImageView ImageView = (ImageView) Findviewbyid (r.id.img);        Imageview.setimageresource (Resources.getsystem (). Getidentifier ("Ic_text_dot", "drawable", "Android"));

Reference: http://stackoverflow.com/questions/3486819/ How-to-resolve-the-error-com-android-internal-r-cannot-be-resolved-when-i-usin

  

  

How Android references resources under the COM.ANDROID.INTERNAL.R directory

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.