2017-04-25 62 views
2

我有一個PreferenceFragment,我想改變背景,文字顏色和其他一些東西,但是我找不到在不影響我應用程序中其他片段的情況下更改片段樣式的方法。如何更改PreferenceFragment風格/主題?

我試圖在Applying custom theme to ActionBar in PreferenceFragment 提到一個解決方案,說把getActivity().setTheme (R.style.myCustomTheme);中的onCreate然而,因爲他們使用的是相同的活性PreferenceFragment影響所有我的其他片段。

有沒有辦法改變只有 prefrencefragment風格不影響活動/其他片段?

謝謝!

編輯:我想我可以使它成爲一個單獨的活動,並改變主題的方式,但我真的很想保持它的片段,如果可能的話。

+0

也在尋找一個解決方案overrid onApplyTheme()... – Denny

回答

-2

可能是你可以在活動

@Override 
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 
    resid = R.style.myCustomTheme; 
    super.onApplyThemeResource(theme, resid, true); 

} 
+0

這種方法不存在。 –

+0

但是在哪裏onApplyTheme()? –

+0

它在Activity中但片段 –