2014-02-24 46 views
1

我正在研究使用延伸@style/Theme.AppCompat.Light.DarkActionBar的主題的應用程序。ActionBarCompat下拉菜單上的造型單選按鈕

在我的活動之一,有一個操作欄圖標顯示了單選按鈕三個選項(這裏是從菜單中XML文件的摘錄):

<item 
    android:icon="@drawable/ic_action_filter_white" 
    android:showAsAction="always" 
    android:title="" 
    preparatest:showAsAction="always"> 
    <menu> 
     <group android:checkableBehavior="single" > 
      <item 
       android:id="@+id/menu_filter_all"      
       android:title="@string/history_list_filter_all" 
       android:checked="true"/> 
      <item 
       android:id="@+id/menu_filter_pending" 
       android:title="@string/history_list_filter_pending"/> 
      <item 
       android:id="@+id/menu_filter_finished" 
       android:title="@string/history_list_filter_finished"/> 
     </group> 
    </menu> 
</item> 

我想給這些單選按鈕自定義樣式,但我不知道該在哪裏做。在我的styles.xml文件我已經定義自定義樣式爲

<style name="RadioButtonPTGreenTheme" parent="android:Widget.CompoundButton.RadioButton"> 
    <item name="android:button">@drawable/ptgreentheme_btn_radio_holo_light</item> 
</style> 

,並使用所有這四個選項試過,但無濟於事:

<item name="android:radioButtonStyle">@style/RadioButtonPTGreenTheme</item>

<item name="android:listChoiceIndicatorSingle">@style/RadioButtonPTGreenTheme</item>

<item name="android:radioButtonStyle">@drawable/ptgreentheme_btn_radio_holo_light</item>

<item name="android:listChoiceIndicatorSingle">@drawable/ptgreentheme_btn_radio_holo_light</item>

有誰知道如何做到這一點?謝謝!

回答

1

看到這個blog post的方式來做到這一點。

長話短說,android:actionBarWidgetTheme用於依賴於操作欄的風格元素,所以android:radioButtonStyle應該把裏面的風格爲actionBarWidgetTheme:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> 
    <item name="android:actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item> 
</style> 

<style name="MyActionBarWidgetTheme" parent="@android:style/Theme.Holo"> 
    <item name="android:radioButtonStyle">@style/MyRadioButtonStyle</item> 
</style> 
+0

非常感謝你,但,使工作! :)你介意我是否編輯你的帖子以添加博客文章中的實際代碼示例? – LuTHieR

+1

Pleasure LuTHieR – Dan

+1

請隨時編輯並添加實際代碼。 – Dan