源码中经常会出现使用android.R.xx的地方或者是在xml文件中出现@android:xxx/xxx。刚开始经常不理解这个是在系统哪里定义过的
后来看到google文档中的定义如下:
Contains resource classes used by applications included in the platform and defines application permissions for system features.
You can use some resources directly from these R
classes in your own applications, but you should generally use only resources that you've provided directly in your application, in order to provide a cohesive application package that has no external dependencies.In particular, you should not use drawable resources from the android
package, because they may change between platform versions, causing unforeseen conflicts with your design. Typically,styles
are the only resources you should use directly from these resources.
你可以在你的应用中通过使用这些R类来使用资源,但是通常应该在应用中使用自定义的唯一的资源,目的是提供一个没有外部依赖的包。特别是,你不应该使用android系统里的图片资源。因为应用在不同版本的平台切换的时候会对你的界面设计及造成不可遇见的冲突。通常,样式风格应该使用自定义的资源。
总结一句话,其实就是说在自己的应用中应该使用自己定义的资源。
android内置的资源还是挺多的,有系统定义的动画、风格、图片等等,具体的可以在谷歌文档上看到。其实这些系统定义的资源都是在framework/base/core/res/res里面的xml文件定义好的。使用android.R.xx或者@android:xxx/xxx其实就是调用这个地方的内容