2013-08-16 65 views
1

在我的應用程序的主題我有dropDownListViewStylespinnerStyle爲整個應用程序。但在一個片段中,我需要微調自定義風格dropDownListViewStyle(我需要改變分頻器)。是否有可能與其他dropDownListViewStyle微調然後設置爲主題?不同dropDownListViewStyles不同的微調風格

在微調樣式或佈局不可能設置下拉分頻器。也不可以在微調器樣式或佈局中設置dropDownListViewStyle。

我真的被困住了,希望有人得到答案。

+1

這是微調在與其他紡紗廠的活動? –

+0

不幸的是。活動包含更多片段(其中一些包含旋轉器),一個片段包含此特殊樣式的旋轉器。 – koso

+0

你會獎勵這個賞金嗎? –

回答

3

不幸的是,在dropDownListViewStyleSpinner是固定的。如果你查看源代碼,你會發現DropdownPopup類,它擴展了ListPopupWindow。在ListPopupWindow類的興趣是DropDownListView在那裏你會找到的構造:

public DropDownListView(Context context, boolean hijackFocus) { 
    super(context, null, com.android.internal.R.attr.dropDownListViewStyle); 
    // ... 
} 

因此,要改變這個是主題,因爲你已經評估的唯一方法。考慮到Spinner正在用於需要基本主題的Activity,我只知道一個解決方法。不幸的是,唯一的辦法是改變Fragment的主題。這意味着全部Spinners在那Fragment將有替代主題。要改變你的Fragment的主題在運行時,在你的onCreateView做到這一點:

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     // create ContextThemeWrapper from the original Activity Context with the custom theme 
     Context context = new ContextThemeWrapper(getActivity(), R.style.My_Custom_Theme); 
     // clone the inflater using the ContextThemeWrapper 
     LayoutInflater localInflater = inflater.cloneInContext(context); 
     // inflate using the cloned inflater, not the passed in default 
     return localInflater.inflate(R.layout.my_layout, container, false); 
    } 

這短暫的,你看創建自定義Spinner,這是不是太困難,考慮到它的開放資源。

+0

非常感謝!你剛剛證實了我的想法。我只是希望我仍然可以忽略某些東西,因爲它很奇怪,使用樣式/主題無法實現這一點。 – koso

+0

很高興爲您提供幫助。現在關於那個賞金...... ;-) –