In Android applications what is the role of “R.java”? [closed]

我们两清 提交于 2019-12-17 07:42:09

问题


Android applications have an automatically generated file called "R.java". Please explain its purpose.

E.g.

  • What is contained in it?
  • What generates it?

Duplicate: What is the concept behind R.java?


回答1:


Every application uses resources such as strings, drawbles, layouts, and styles. Instead of hard coding such resources into an application, one externalizes them and refers to them by ID. The R.java file contains all those resource IDs, whether assigned by the programmer or generated by the sdk.




回答2:


R.java is where you have access to anything you have in your resources:

  • Drawables
  • Layouts
  • Strings
  • Arrays
  • ....etc

You can read more here.




回答3:


R.java is autogenerated on build. It's content is based on the resource files (including layouts and preferences).

When you delete it, it gets recreated, but if you create your own, you will get into trouble as the build system will not be able to replace it.



来源:https://stackoverflow.com/questions/11698808/in-android-applications-what-is-the-role-of-r-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!