5
好工作,我意識到,對於Context.getTheme()
,它通常並不好,如果我們使用Application
作爲Context
爲什麼getTheme不會對應用
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
屬性?
在清單中,我們在Application
級別找到了具體的主題信息。所以,我認爲從Application
獲得主題確實有意義。
<application
android:theme="..."