如何将库项目中的可绘制对象引用到 android 中的主项目布局中?

发布于 2024-11-14 04:29:14 字数 395 浏览 6 评论 0原文

我有一个 android 库项目和其中可重用的可绘制资源。
假设包名称是:com.vijay.mylib;

然后我有一个主项目,它使用上面的库项目。
假设它的包名称是:com.vijay.myproject

考虑到我已正确地将库项目与我的主项目链接起来。

在我的主项目中,我有一个名为 main.xml 的布局。 我想在 main.xml 中使用一些可绘制的 ROM 库项目。 我怎样才能在 xml 中做到这一点?
以正常方式引用“@drawable/myImage”对我来说不起作用。参考选择器窗口仅向我显示主项目中的可绘制对象。不是来自图书馆项目。

(注意:两个项目都有不同的 R.java 包。它与此有什么关系吗?)

I have a android library project and reusable drawable resources in it.

Lets say package name is: com.vijay.mylib;

Then i have a main project and it uses the above library project.

Lets say its package name is:com.vijay.myproject.

Consider that I have linked library project with my main project correctly.

In my main project i have a layout called main.xml.
I want to use some drawable rom library project in main.xml.
How can i do it in xml?
Refering in normal way like "@drawable/myImage" didn't work for me. The referece chooser windows shows me the drawables only from main project. Not from library project.

(Note : Both projects have different package for R.java. Does it has do anything with this?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滥情稳全场 2024-11-21 04:29:14

您可能需要为库添加您自己的 uri 并使用它来引用可绘制对象。

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

然后你应该能够使用以下方式访问可绘制对象

@vijay:drawable/myImage

You probably would need to add your own uri for library and use it to refer to drawable.

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

Then you should be able to access drawable using

@vijay:drawable/myImage
岁月无声 2024-11-21 04:29:14

确定在库项目(lib 项目)和应用程序项目(app 项目)之间使用哪些可绘制资源的最佳方法是通过设计:

  1. 默认情况下,应用程序项目的可绘制资源将取代同名的可绘制资源的使用lib 项目的可绘制资源。因此,确保使用 lib 项目资源的最佳方法是从应用程序项目中完全删除该资源。

  2. 我遇到的另一个问题是,如果您希望优先使用应用程序项目资源,请确保应用程序项目中的可绘制文件夹名称与应用程序项目中的资源文件夹名称​​相同图书馆项目。即,如果您的 lib 项目资源位于 drawable-mdpi 中,请确保该文件夹在应用程序项目中也称为 drawable-mdpi

The best way to determine which drawable resources are used between a library project (lib project) and an application project (app project) is down to design:

  1. By default, an app project's drawable resource will supersede the use of an identically named lib project's drawable resource. Therefore, the best way to ensure the lib project resource is used, is to remove the resource from the app project altogether.

  2. Another issue i came across is that if you want the app project resource to be used in preference, be sure that the drawable folder name in the app project is identical to the resource folder name in the library project. I.e. if your lib project resources live in drawable-mdpi, ensure the folder is called drawable-mdpi in the app project too!

放血 2024-11-21 04:29:14

到了 2022 年,如果将 lib 导入到您的项目中,就很容易使用,如下图所示。

1- 你想在哪里使用它,只需编写 R.drawable.any_png

2- 打开左侧的图标,然后选择 libraries

3- 你可以看到所有图片位于 3,2 中的两个位置
输入图片此处描述

In 2022, it's easy to use, if the lib is imported to your project, as it's shown in below picture.

1- where do you want use it, just write R.drawable.any_png

2- open icon in left side, then chose the libraries item

3- you can see all the pictures are in two place in 3,2
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文