为多个项目重用类文件和资源
背景:
我目前正在开发一个 Android 应用程序,它使用自定义对话框来提示输入密码。展望未来,我希望能够在我未来的项目中以最少的配置使用此对话框(完整)。
问题:
有什么方法可以将此对话框的所有代码和 XML 封装到一个包中吗?理想情况下,我想简单地导入对话框并完成它。使用代码可以很容易地做到这一点,但我不确定如何使用 XML 布局和字符串资源文件来做到这一点。基本上,我只是不想为每个项目手动将字符串元素添加到 strings.xml 文件中,也不必复制(从而重复)我的布局。我考虑过将字符串/布局硬编码到代码中,但这似乎是不好的做法(即使只有 4-5 个字符串和 2 个文本框)。
那么,最好的方法是什么?
Background:
I am currently developing an Android application that makes use of a custom dialog to prompt for a password. Thinking ahead, I would like to be able to use this dialog (in its entirety) in my future projects with a minimum of configuration.
Question:
Is there any way I can encapsulate all of the code and XML for this dialog into one package? Ideally, I would like to simply import the dialog and be done with it. This is easy enough to do with the code, but I am not sure how to do this with the XML layout and string resources files. Basically, I just don't want to have to manually add the string elements to my strings.xml file for each project as well as not have to copy (and thus duplicate) my layout. I gave thought to hard-coding strings / layout into the code, but that seems like bad practice (even for only 4-5 strings and 2 textboxes).
So, what would be the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个库项目 ,允许共享代码和资源。
You need to create a library project, that allows to share both code and resources.