java - 带有 ContextThemeWrapper 的 LayoutInflater 并不总是主题化

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

我正在尝试使用与应用程序默认主题不同的主题来 inflated layout ,并这样做:

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

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

编辑: 我无法设置 android:theme 因为我以动态方式获取主题。

最佳答案

我首先在Activity.onCreate中创建了 View 。通过一些测试,我发现如果我在 Activity.onWindowFocusChanged(boolean hasFocus) 中创建 View ,当 hasFocus == true 时效果很好。我还是不知道为什么。

关于java - 带有 ContextThemeWrapper 的 LayoutInflater 并不总是主题化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31636875/

相关文章:

java - 以编程方式静默安装 APK

android - bada中是否有类似于android中的 "Context"的类?

android - 没有在 fragment 中获取 Activity 的上下文

java - 右加入jpa

java - 如何从自定义JButton拦截paintComponent

java - 当各种设备同时使用该功能时,HttpClient 出现问题

Android 检查键盘输入

android - 在android中执行sql查询的方式有何不同?

java - 使用 java opts 将 file.encoding 设置为无效字符集

java - Files.walkFileTree中的遍历顺序