your java code where you manage checkbox
click event
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem check = menu.findItem(R.id.action_checkbox);
CheckBox c_box =(CheckBox) check.getActionView();
c_box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
Toast.makeText(getActivity(), "checked",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getActivity(), "unchecked",
Toast.LENGTH_SHORT).show();
}
}
});
return true;
}
your menu looks like ok
<item
android:id="@+id/action_checkbox"
app:actionViewClass="android.widget.CheckBox"
android:title="@string/action_check"
app:showAsAction="always"
/>
Hope it works.. let me know if you face any problem.