Android - Difference between View.getResources() and View.getContext().getResources()

android, android-view

Solution

Nothing. As seen in the source code:

private final Resources mResources;

public View(Context context) {
    mContext = context;
    mResources = context != null ? context.getResources() : null;
    ...
}

public Resources getResources() {
    return mResources;
}

Problem

I wanted to understand the real difference in using `View.getResources()` and `View.getContext().getResources()`. For example, I have to set a color to a `TextView` from resource.. ``` view.setTextColor(view.getResources().getColor(R.color.Blue)); ``` or ``` view.setTextColor(view.getContext().getResources().getColor(R.color.Blue)); ``` Both works , but as per the documents... `View.getResources()` - Returns the resources associated with this view. `View.getContext()` - Returns the context the view is running in, through which it can access the current theme, resources, etc. Your thoughts are welcome....

Original source