我意识到,对于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对象获取主题确实有意义.

android:theme="..."

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐