getResources的执行情况()的Android [英] Implementation of getResources() Android
问题描述
我刚开始学习机器人编程,我想出了一个关于方法getResources疑问()。
我注意到,当我创建的资源对象的所有我需要做的就是:
资源资源= getResources();
维基,首先怀疑是下面为什么我已经做的那样,我不能使用Java的关键字新?我不应该做这样的事情:
资源资源=新资源();
第二个疑问是:我的文件的顶部,我已经导入了资源类。
进口android.content.res.Resources;
现在我读了Android的API和它说,getResources()是一个公共的抽象方法,如果它是抽象的类实现它?我怎么能简单地把它输入getResources(),如果它不声明为静态的?
I have just started learning android programming and I came up with a doubt about the method getResources().
I noticed that when I create a Resources object all I have to do is:
Resources res = getResources();
The first doubt is the following why do I have to do in that way and I mustn't use the java keyword new? Shouldn't I do something like this:
Resources res = new Resources();
The second doubt is the following: at the top of my file I have imported the Resources class.
import android.content.res.Resources;
Now I read the android api and it says that getResources() is a public abstract method, if it is abstract which class implements it? how can I simply call it typing getResources() if it is not declared as static?
推荐答案
您的活动扩展类的 android.app.Activity 从而扩展了类 android.content .Context (三级起来的类层次结构)。类上下文
声明抽象方法的 getResources(),它意味着您的活动子类继承的方法,你可以从你的的onCreate()
方法中调用它(例如)。
Your activity extends class android.app.Activity which in turn extends class android.content.Context (three levels up the class hierarchy). Class Context
declares the abstract method getResources() which means that your activity subclass inherits that method and you can call it from within your onCreate()
method (for example).
方法 getResources()
被声明为抽象类上下文
,但中间类的类中的一个层次结构( android.view.ContextThemeWrapper )提供了方法的实现。
The method getResources()
is declared as abstract in class Context
but one of the intermediate classes in the class hierarchy (android.view.ContextThemeWrapper) provides an implementation for the method.
另外这意味着创建资源
的对象是不是你的责任;它由框架代替进行。
Also that means that creating the Resources
object is not your responsibility; it is done by the framework instead.
这篇关于getResources的执行情况()的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!