Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom CheckBox menu item ActionBar not work

Tags:

android

i have problem with styling Custom CheckBox Menu Item ActionBar. I have implemented, but It's not styled.

enter image description here

I want to changed with resource this

if checkbox is checked

enter image description here

if checkbox is not checked

enter image description here

this is my menu item Action Bar.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.tracking.bus.maps.SingleViewMapsActivity" >

        <item
        android:id="@+id/actionbar_alarm"
        android:title="@string/actionbar_alarm"
        app:actionViewClass="android.widget.CheckBox"
        app:showAsAction="ifRoom"/>

        <item
        android:id="@+id/actionbar_interval"
        android:title="@string/actionbar_interval"
        app:actionViewClass="android.widget.Spinner"
        app:showAsAction="ifRoom"/>

        <item
        android:id="@+id/actionbar_log_track"
        android:title="@string/actionbar_log_track"
        app:showAsAction="never"/>
</menu>

style Action Bar

    <style name="Theme.Myab" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarItemBackground">@drawable/selectable_background_myab</item>
        <item name="popupMenuStyle">@style/PopupMenu.Myab</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Myab</item>
        <item name="actionBarTabStyle">@style/ActionBarTabStyle.Myab</item>
        <item name="actionDropDownStyle">@style/DropDownNav.Myab</item>
        <item name="actionBarStyle">@style/ActionBar.Solid.Myab</item>
        <item name="actionModeBackground">@drawable/cab_background_top_myab</item>
        <item name="actionModeSplitBackground">@drawable/cab_background_bottom_myab</item>
        <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Myab</item>
        <item name="spinnerDropDownItemStyle">@style/DropDownItem.Myab</item>
        <item name="android:spinnerItemStyle">@style/SpinnerItem.Myab</item>        
        <item name="android:checkboxStyle">@style/customCheckBoxStyle.Myab</item>
        <item name="actionBarWidgetTheme">@style/Theme.Myab.Widget</item>   
    </style>

   <!-- style checkbox -->      
  <style name="customCheckBoxStyle.Myab" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/custom_checkbox_design</item>
    </style>

custom_checkbox_design.xml

<?xml version="1.0" encoding="utf-8"?>     
    <selector xmlns:android="http://schemas.android.com/apk/res/android">     
         <item android:state_checked="true" android:drawable="@drawable/alram_on" />
         <item android:state_checked="false" android:drawable="@drawable/alram_off" />     
    </selector>

so how to solve it ? thanks sorry for my english

like image 628
Amay Diam Avatar asked Sep 30 '22 11:09

Amay Diam


1 Answers

First things, android:checkboxStyle should run on device with API 11 or later.

Try set your checkbox selector like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android" android:enterFadeDuration="300">
    <item android:state_selected="true" android:drawable="@drawable/checked"></item>
    <item android:state_checked="true" android:drawable="@drawable/checked"></item>
    <item android:drawable="@drawable/unchecked"></item> <!--default state, unchecked-->
</selector>
like image 102
leegor Avatar answered Oct 03 '22 01:10

leegor