I need to put a Checkbox in my Android Action bar, it's work but i need to set an Image in the place of Checkbox text. When I run my app on my phone the image is shifting in and out of the screen. The icone is good when i run it in emulator.
Icon Ok in my genymotion emulator
Icone go out of screen on my physical device !
For add the button to the Checkbox I use this :
ChB_GroupRef.setButtonDrawable(R.drawable.bouton_dispatcher);
Maybe is the wrong way...
My menu :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_previsualiser_inventaire, menu);
ChB_GroupRef = (CheckBox) menu.findItem(R.id.ChB_GroupRef).getActionView();
ChB_GroupRef.setButtonDrawable(R.drawable.bouton_grouper);
ChB_GroupRef.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (((CheckBox) view).isChecked()) {
//Cocher = Group des refs
ChB_GroupRef.setButtonDrawable(R.drawable.bouton_dispatcher);
System.out.println("Checked");
} else {
//DeCocher = Pas de groupement
ChB_GroupRef.setButtonDrawable(R.drawable.bouton_grouper);
System.out.println("UnChecked");
}
}
});
return true;
}
My Menu XML :
<menu xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
tools:context="...">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
<item
android:id="@+id/ChB_GroupRef"
android:actionViewClass="android.widget.CheckBox"
android:title="Grouper Ref"
android:showAsAction="always"/>
I think i need to use a margin or padding but I don't know how it's work with the action bar, i've found nothing in my search.
Aucun commentaire:
Enregistrer un commentaire