我已尝试使用此answer在工具栏menuitem中的单选按钮上应用样式,但它对我不起作用。我想在MenuItem中为单选按钮应用复选标记样式,所以请帮助我正确指导。
Style.xml
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorAccent">@color/colorPrimary</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@color/activity_bg</item>
<item name="android:windowDisablePreview">true</item>
<item name="alertDialogTheme">@style/AlertDialogCustom</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item>
<item name="actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="MyActionBarWidgetTheme" parent="android:Theme.Holo.Light">
<!--<item name="android:listChoiceIndicatorMultiple">@drawable/radiobutton_selector_checkmark</item>-->
<item name="android:radioButtonStyle">@style/Widget.RadioButton.CheckMark</item>
</style>
<style name="Widget.RadioButton.CheckMark" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:textColor">@android:color/holo_red_light</item>
<item name="android:button">@drawable/radiobutton_selector</item>
<item name="android:background">@drawable/radiobutton_selector</item>
</style>
这是输出
menu.xml文件
<item
android:id="@+id/action_filter"
android:icon="@drawable/ic_action_filter_white_24dp"
android:orderInCategory="2"
android:title="@string/action_filter"
app:showAsAction="always">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/filter_favorite"
android:title="Favorites"
android:checked="true"
app:showAsAction="never"/>
<item
android:id="@+id/filter_myProject"
android:title="My Projects"
app:showAsAction="never"/>
<item
android:id="@+id/filter_completed"
android:title="Completed"
app:showAsAction="never"/>
<item
android:id="@+id/filter_all"
android:title="All Projects"
app:showAsAction="never"/>
</group>
</menu>
答案 0 :(得分:0)
我知道这是一篇过时的文章,但是如果有人在寻找答案,请点击以下链接(详细内容在结尾):https://www.zoftino.com/android-ui-control-radiobutton
您必须使用selector
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/radio_checked" />
<item android:drawable="@drawable/radio_unchecked" />
</selector>
其中drawable/radio_checked
和drawable/radio_unchecked
是您的假复选框。