Why getTheme not working on Application

I understand that for Context.getTheme()it usually does not work if we use ApplicationbothContext

MyApplication.singletonInstance().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId will be 0x0, which is invalid

However, if I use Activityas context, it works well

MyFragment.this.getActivity().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId is valid

I was wondering why we cannot resolve the attribute through Application?

In the manifest we provide specific information about the topic at the level Application. So, I thought getting a topic from an object made Applicationsense.

<application
    android:theme="..."
+5
source share
1 answer

This does not work because, apparently, the object returned getApplicationContext()is not a complete Contextobject, as stated in this CommonsWare answer :

Context, , Activity. , Context, , .

Context , :

getApplicationContext().getTheme().applyStyle(R.style.MyTheme, true);

Android dev; Activity , , getTheme().

+3

All Articles