在XML文件中引用支持库中的资源ID

时间:2017-01-12 21:01:45

标签: java android xml android-support-library

导入使用在v7 supoort库中创建的资源ID的xml文件。

导入的xml文件包含以下ID但不使用" @id +,"好像它刚刚创建:

机器人:ID =" @ ID / activity_chooser_view_content"

在以下链接中,它显示在v7 appCompat支持库中已创建id(在评论结束后第3行向下):

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r1/frameworks/support/v7/appcompat/res/layout/abc_activity_chooser_view.xml

 android:id="@+id/activity_chooser_view_content"

为了让Android或Android Studio找到ID,我必须做些什么?

我收到以下错误:

Error:(2, 51) No resource found that matches the given name (at 'id' with value '@id/activity_chooser_view_content').

Error:(8, 64) No resource found that matches the given name (at 'id' with value '@id/image').

我正在编译以下参考库:

compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'


compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v13:25.0.0'

1 个答案:

答案 0 :(得分:0)

要从SDK引用ID,您需要inflater = LayoutInflater.from(mContext);

或者,您的错误表示由于您有@android:id/<name>而非@id,因此您尝试从自己应用的资源中引用现有ID ,而不是创建新的一。

或许你应该尝试像

这样的东西
@+id

值得一提......

  

内部布局不应直接使用,并且可能随时更改,这可能会在将来破坏您的代码。更好的解决方案是创建自己的布局或使用具有类似功能的公共框架小部件。使用内部小部件需要您自担风险

https://stackoverflow.com/a/39318656/2308683