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....
I would guess the View.getResources()
is a shortcut for getContext().getResources()
.
You could search the source code if you really want to know.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With