2016-06-07 28 views
0

如何将主题设置为片段?将主题设置为片段

下面的代码不适用于我,或者我错了什么地方?

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); 
} 
+1

[设置主题为片段]可能的重复(http://stackoverflow.com/questions/9469174/set-theme-for-a-fragment) –

回答

0

上面的代码将改变片段布局中的小部件的主题,但它不会更改ActionBar和状态栏的主题。

添加一个SeekBar和一个切换到你的片段布局,看看它的主题已经改变或没有。