Inflater - 获得主题背景不起作用

时间:2015-03-21 21:14:32

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

在我的基础对话框类中,我使用以下内容:

IDialogThemeProvider themeProvider = Functions.tryConvert(IDialogThemeProvider.class, getActivity());
if (themeProvider != null && themeProvider.getDialogThemeResId() != null)
        inflater = LayoutInflater.from(new ContextThemeWrapper(getActivity(), themeProvider.getDialogThemeResId()));

所以之后我有一个带有正确主题背景的inflater。之后我用两种方式使用这种inflater:

  1. inflater.inflate(...) =>这非常好用,并使用提供的主题
  2. TextView tv = new TextView(inflater.getContext()) =>这不起作用,这使用默认主题而不是inflater中使用的主题
  3. 我该如何解决?我可能可以提供主题背景,但实际上,我应该能够以某种方式从这个背景中得到这个背景......

1 个答案:

答案 0 :(得分:0)

  1. 我现在尝试使用带有主题上下文的视图的3 arg构造函数... =>不起作用
  2. 我尝试直接使用主题上下文=>不起作用
  3. 只有有效的解决方案是,从xml中扩展视图。因此,对于我的用例,我创建了一个checkbox.xml和一个edittext.xml并使用这些布局。这应该至少总是有效...