我意识到,对于Context.getTheme()
,如果我们Application
用作Context
MyApplication.singletonInstance().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId will be 0x0, which is invalid
但是,如果我Activity
用作上下文,则效果很好
MyFragment.this.getActivity().getTheme().resolveAttribute(R.attr.actionBarDeleteIcon, typedValue, true);
// typedValue.resourceId is valid
我想知道为什么我们不能通过解析属性Application
?
在 manifest 中,我们可以在Application
level 中找到特定的主题信息。所以,我认为从Application
对象中获取主题确实有意义。
<application
android:theme="..."