0

I have seen it done in apps like QuickPic where they managed to put the icon on right side

enter image description here

I tried to make the same thing but then I realized the icon seems to be hard-coded to appear on the left side.

enter image description here

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?

flamyoad
  • 519
  • 7
  • 15

2 Answers2

3

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" />
chand mohd
  • 2,363
  • 1
  • 14
  • 27
1

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

snachmsm
  • 17,866
  • 3
  • 32
  • 74