简体   繁体   English

如何从Android的Activity类中引用另一个项目的layout / xml文件?

[英]How can I refer to layout/xml files of another project from my Activity class in Android?

I have two Android projects in my Workspace. 我的Workspace中有两个Android项目。 Now, I want to access the res/layout files of second project in the activity/Java class of my first project. 现在,我想访问第一个项目的activity / Java类中第二个项目的res / layout文件。

I have already added the second project as a library of first project but its not working. 我已经将第二个项目添加为第一个项目的库,但它不起作用。 Do I need to give the path in setContentView(R.layout.main) or something like that. 我是否需要在setContentView(R.layout.main)或类似的东西中给出路径。 Please suggest. 请建议。

FYI: I am working on 4.2 version of Android. 仅供参考:我正在开发4.2版Android。

Regards, Anupriya 此致,Anupriya

我已尝试使用相同的结果你可以直接访问布局文件及其名称添加库后请清理项目,然后尝试从另一个项目的资源文件夹中访问文件,即

setContentView(R.layout.layout_from_other_project);

You probably would need to add your own uri for library and use it to refer to drawable. 您可能需要为库添加自己的uri并使用它来引用drawable。

xmlns:libProj="http://schemas.android.com/apk/res/com.test.mylib"

Then you should be able to access drawable using 然后你应该能够访问drawable使用

@libProj:drawable/myImage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 How to move from one activity to another ie Java Class to Kotlin Class in an Android Java Project? - How to move from one activity to another i.e Java Class to Kotlin Class in an Android Java Project? 我如何引用另一个类的对象 - how can I refer to an object of another class 如何从AWT将类导入我的Android项目? - How can I import a class from AWT into my Android project? 如何在扩展Activity的类中访问布局,该类将由另一个Activity子类化? - How can I access the layout in a class extending Activity that is to be subclassed by another Activity? 编程为android,当我构建项目时,我的布局xml文件不会更新 - Programming to android, My layout xml files won't update when i build the project 如何在Java中动态运行时将.class文件从一个项目(项目2)加载到另一个Web项目(项目3)? - How can I load .class files from one project(project 2) to another web project(Project 3) at dynamically runtime in java? Java反思:如何在不将另一个项目或JAR添加到我的类路径的情况下从另一个项目加载一个类? - Java reflection: How can I load a class from another project without adding that project or JAR to my classpath? 如何在Android应用程序中全局访问另一个班级的活动? - How can I access an Activity from another class globally in an Android app? 无法使按钮引用android中的另一个活动 - Can't make the button refer to another activity in android 如何在我的Android项目中使用第二个Java类? - How can I use a second Java class in my Android project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM