簡體   English   中英

如何在Android中的MenuItem中顯示文本右側的圖標?

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

當我使用ActionBar時,可以像在Android中一樣將圖標添加到MenuItems中。 但是圖標始終在文本的左側。 我可以將圖標以某種方式放在右側嗎?

這是我的代碼:

 <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>

自定義布局:

<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>

菜單圖片

嘗試這樣可能會幫助您,

<?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