ContextInflater与ContextThemeWrapper并不总是主题

时间:2015-07-26 12:19:43

标签: java android android-context android-theme layout-inflater

我正在尝试使用与app default不同的主题来扩充布局,并按照以下方式进行:

final View view = context.getLayoutInflater().cloneInContext(new ContextThemeWrapper(context, getThemeForView())).inflate(R.layout.some_layout, root, false);

第一次完成视图没有我想要的主题,但主要的应用主题。几分钟后重新创建视图时,它具有正确的主题。为什么首次创建视图时主题会有所不同?

编辑: 我无法设置android:theme,因为我的主题是恐怖主义。

2 个答案:

答案 0 :(得分:3)

我首先在Activity.onCreate创建了视图。通过一些测试,我发现如果Activity.onWindowFocusChanged(boolean hasFocus) hasFocus == true工作正常,我会在z=0 for x in range(0,1000,1): if type(x%3)==int or type(x%5)==int: z=x+z print z 创建视图。我还不确定为什么。

答案 1 :(得分:0)

您可以添加

android:theme="@style/some_theme"

清单文件中的活动。