Android 为什么getTheme没有';我在申请方面做得不好

Android 为什么getTheme没有';我在申请方面做得不好,android,Android,我意识到,对于Context.getTheme(),如果我们使用应用程序作为上下文 MyApplication.singletonInstance().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true); // typedValue.resourceId will be 0x0, which is invalid 但是,如果我使用活动作为上下文,则效果很好 MyFragment.this.getAc

我意识到,对于
Context.getTheme()
,如果我们使用
应用程序
作为
上下文

MyApplication.singletonInstance().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId will be 0x0, which is invalid
但是,如果我使用
活动
作为上下文,则效果很好

MyFragment.this.getActivity().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId is valid
我想知道为什么我们不能通过
应用程序
解析属性

在清单中,我们可以在
应用程序
级别找到特定的主题信息。所以,我认为从
应用程序
对象中获取主题是有意义的

<application
    android:theme="..."

它不起作用,因为
getApplicationContext()
返回的对象显然不是一个完整的
上下文
对象,如下所述:

它不是一个完整的
上下文
,支持
活动
所做的一切。您尝试使用此
上下文执行的各种操作都将失败,主要与GUI有关

一种可能的解决方案是在
上下文中手动设置主题,如下所示:

getApplicationContext().getTheme().applyStyle(R.style.MyTheme, true);
但这种方法并没有得到Android开发团队的认可;正确的解决方案是使用
Activity
处理与UI相关的事情,比如
getTheme()