Android: Difference between a System Resource and an Application Resource? [duplicate]

[亡魂溺海] 提交于 2019-12-11 04:00:06

问题


From Android documentation for the Resources class:

public static Resources getSystem ()

Added in API level 1 Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

What are system resources and application resources and what is the difference between them?


回答1:


Application resources are

  1. Animation Resources (R.anim) --> res/anim
  2. Color State List Resource(R.color) --> res/color
  3. Drawable Resources (R.drawable) --> res/drawable
  4. Layout Resource (R.layout) -- >res/layout

see this link for more details


System resources are

  1. Android ids (android.R.id)
  2. Android's widgets (android:id/tabs)
  3. Color (android.R.color.transparent)

see this post for more details




回答2:


System Resources:

Android OS by default as has some resources which it uses in many places like cancel and ok strings. Event image resources like close icon and many more. One can use the directly in your application by getting that resource. As it's static, so can use it Absolutely everywhere

Resources.getSystem().getString(android.R.string.cancel);//for system resources only

  • For System resources you use android.R.(anim, color, string, id, drawable)

Application Resources:

In your application you have many strings which you use it in many UI Components which is meant to change dynamically on the scenario basis for that purpose you're going to use your application resources. You need a context to get that application resources as it's not static one.

getApplicationContext().getResource().getString(R.string.cancel);//cancel string which you've define in values/strings.xml
  • For application you use R.(anim,drawable,id,string,color)


来源:https://stackoverflow.com/questions/32021821/android-difference-between-a-system-resource-and-an-application-resource

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