2016-06-07 27 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和一個切換到你的片段佈局,看看它的主題已經改變或沒有。