The import com.android.internal.R cannot be resolved

后端 未结 4 826
悲&欢浪女
悲&欢浪女 2020-12-29 09:08

Hi i am working with Gestures and i need to import but i m getting error

com.android.internal.R;

The import com.android.internal.R

相关标签:
4条回答
  • 2020-12-29 09:20

    Yes you can use the internal R with some dirty trick (dirty trick = Java reflection).

    Just an example:

    Class clasz = Class.forName("com.android.internal.R$styleable")
    Field field = clasz.getDeclaredField("TextAppearance");
    field.setAccessible(true);
    int[] textAppearanceStyleArr = (int[])field.get(null);
    
    field = clasz.getDeclaredField("TextAppearance_textSize");
    field.setAccessible(true);
    int textSizeStyle = (Integer)field.get(null);
    
    0 讨论(0)
  • 2020-12-29 09:33

    First of all, what is Gestures ? Do you have a package named com.android.internal in your gen folder ? Doest it contain R.java ? If not, try Project->Clean in Eclipse. If it still doesn't work, you may have an error in your XML layout files.

    0 讨论(0)
  • 2020-12-29 09:39

    I have a couple suggestions:

    1) Make sure you don't have any other errors other than the R-related errors. Right-click your project folder in Eclipse, Android Tools -> Fix Project Properties.

    2) Check to make sure you have the correct R imported. Sometimes the default Android.R can be imported.

    0 讨论(0)
  • 2020-12-29 09:44

    You don't say why you need access to com.android.internal.R, but the sad fact is that you simply cannot import it (the "internal" is a clue that it's not part of the public API). Google doesn't expose this because it is subject to change.

    It is possible to get to the internal resources by calling Resources.getSystem(). To get the value of a particular resource identifier, you have to know its name and then use code like the following to find the value:

    Resources res = Resources.getSystem();
    int id = res.getIdentifier("resource name", "resource type", "android");
    

    Be aware that any name that you use could disappear in future versions of Android.

    0 讨论(0)
提交回复
热议问题