Solution 1 :
you can always use android:actionLayout
and create your own View that looks the way you want.
Example:
your_custum_view:
<LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto"
android_layout_height="wrap_content"
android_layout_width="wrap_content"
android_orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android_id="@+id/tvMenu"
android_clickable="true"
android_layout_height="wrap_content"
android_layout_width="wrap_content"
app_drawableRightCompat="@drawable/ic_up_arrow"
android_drawablePadding="@dimen/margin_medium"
android_focusable="true"
android_gravity="center"
android_padding="6dp"
android_orientation="vertical"
android_text="By Name" />
your_menu:
<item
android_id="@+id/nv_create"
android_icon="@drawable/ic_create_dw"
android_title="Create"
app_actionLayout="@layout/menu_sign"
app_showAsAction="always" />
Solution 2 :
no such option in XML, but you can do it in Java/Kotlin. For start try to use ImageSpan
and re-set this whole text in onCreateOptionsMenu
. HERE you have some examples how to handle this span
Problem :
I have seen it done in apps like QuickPic where they managed to put the icon on right side
I tried to make the same thing but then I realized the icon seems to be hard-coded to appear on the left side.
Below is my menu.xml
<menu>
<item android_id="@+id/sort_by_name"
android_title="By name"
android_icon="@drawable/ic_arrow_downward_gray_24dp"
/>
<item android_id="@+id/sort_by_date"
android_title="By date"/>
<item android_id="@+id/sort_by_path"
android_title="By path"/>
</menu>
So is there any way to move the icon to the right side?
Comments
Comment posted by snachmsm
more complex, but also more flexible solution with a lot more possibilities. +1