如何将主题设置为片段?
下面的代码对我不起作用,或者我错了?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.yourCustomTheme);
// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
// inflate the layout using the cloned inflater, not default inflater
return localInflater.inflate(R.layout.yourLayout, container, false);
}
答案 0 :(得分:0)
上面的代码将更改片段布局中窗口小部件的主题,但不会更改ActionBar和状态栏的主题。
将SeekBar和Switch添加到您的片段布局中,看看它的主题是否已更改。