简体   繁体   中英

How to display the icon of the right side of the Text in an MenuItem in Android?

When i use the ActionBar i can add icons to the MenuItems as i would in Android. But the icons are always on the left side of the text. Can i place the icon on the right side somehow?

This my code:

 <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" >
    <item
     android:id="@+id/forgetpassword"
     android:icon="@drawable/usermodify"
     android:title="@string/Forgetpass"
     app:showAsAction="always|withText"/>
</menu>

custom layout:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="3dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dp"
            android:text="@string/complogo" />

        <ImageView
            android:id="@+id/img1"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginTop="2dp"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

菜单图片

try like this may help you,

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/forgetpassword"
        android:title="@string/Forgetpass"
        app:actionLayout="@layout/your_custom_layout"
        app:showAsAction="always"/>
</menu>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM