简体   繁体   English

如何在Android中的MenuItem中显示文本右侧的图标?

[英]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. 当我使用ActionBar时,可以像在Android中一样将图标添加到MenuItems中。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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