I have an overflow menu with a checkable menu item. I would like to align the CheckBox all the way to the end, but I don't know how this can be done.
My menu is defined like so:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/ic_baseline_more_vert_24"
android:title=""
app:showAsAction="always">
<menu>
<item
android:id="@+id/desktop_site"
android:checkable="true"
android:checked="false"
android:icon="@drawable/ic_baseline_desktop_windows_24"
android:title="Desktop site"
app:showAsAction="never" />
</menu>
</item>
</menu>


You can create a custom style to the
CheckBoxand adjust the end padding with a negative value:And apply it to your app's theme:
Note: By default there should be some margin surrounds a menu item; so you can't send the
checkBoxto the far end, as its right edge will cut:When using -8dp:
So, you need to be careful in handling this.
UPDATE
This requires to reverse this padding in all of
CheckBoxesin your layouts; and there are options for this:android:paddingRight="7dp"/android:paddingEnd="7dp"to all theCheckBoxes.CheckBoxclass and add this padding to its constructors; and use this customized CheckBox instead of the defaultCheckBox:And to use it:
Hint: If you target API-17+, then use
android:paddingEndinsteadandroid:paddingRight