大家好,我正在使用手势技术,但在导入时遇到了错误。
com.android.internal.R;
无法解析导入 com.android.internal.R
请求帮助,谢谢。
com.android.internal.R
,但不幸的是你无法导入它("internal" 暗示它不是公共 API 的一部分)。Google 不暴露这个因为它可能会发生变化。Resources.getSystem()
可以访问内部资源。要获取特定资源标识符的值,你必须知道它的名称,然后使用以下类似的代码来查找该值:Resources res = Resources.getSystem();
int id = res.getIdentifier("resource name", "resource type", "android");
请注意,您使用的任何名称在未来的Android版本中都可能消失。
<item type="id" name="switch_widget" />
- nAkhmedovid
资源定义,你可以在代码中引用它作为R.id.switch_widget
。你还有其他想法吗? - Ted Hopp我有几个建议:
1)确保您除了R相关的错误之外,没有其他的错误。在Eclipse中右键单击您的项目文件夹,选择Android工具->修复项目属性。
2)检查您是否导入了正确的R。有时会导入默认的Android.R。
是的,你可以使用一些“肮脏的技巧”(即Java反射)来使用内部R。
这里是一个例子:
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);
首先,什么是手势?
你的gen文件夹中是否有名为com.android.internal的包?它是否包含R.java?如果没有,请尝试在Eclipse中选择Project->Clean。如果仍然无法正常工作,则可能存在XML布局文件中的错误。