【问题标题】:android - action bar menu - move icons to the right sideandroid - 操作栏菜单 - 将图标移动到右侧
【发布时间】:2014-07-25 11:10:14
【问题描述】:

我在操作栏的子菜单项中添加了图标,但图标出现在左侧,我希望它们出现在右侧。

截图:

代码:

    <menu>
     <item android:id="@+id/item6" android:title="יועצת וירטואלית" android:icon="@drawable/chaticon"></item>
    <item android:id="@+id/item1" android:title="מעקב" android:icon="@drawable/iconinfo"></item>
</menu>

【问题讨论】:

  • 我认为可能是 RTL 的问题。

标签: android android-activity android-xml


【解决方案1】:

你的意思是导航抽屉, 可以自定义抽屉式导航完全看视频教程here也给出了源代码。

您只需使用此代码更改custom_drawer_item.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
      android:id="@+id/itemLayout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:orientation="vertical"

      android:layout_marginTop="0dp"
      android:background="?android:attr/activatedBackgroundIndicator"
     >

              <LinearLayout

                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:minHeight="55dp"
                 >


                  <TextView
                      android:id="@+id/drawer_itemName"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textAppearance="?android:attr/textAppearanceLarge"
                      />

                  <ImageView
                      android:id="@+id/drawer_icon"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      />


              </LinearLayout>

               <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:layout_marginBottom="1dp"
      android:layout_marginTop="1dp"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:background="#DADADC"

       ></View>

    </LinearLayout>

</RelativeLayout>

【讨论】:

    【解决方案2】:

    试试

    android:orderInCategory="2"
    

    对于第一个项目和

    android:orderInCategory="1"
    

    这可能会按顺序排列项目,从而允许进行您描述的配置。

    【讨论】:

      【解决方案3】:

      您需要创建一个自定义视图并将其设置为您要更改的特定菜单项的操作视图。请参考此帖:https://stackoverflow.com/a/17333227/1134429

      【讨论】:

        【解决方案4】:

        如果你真的想这样做,你可以使用popuwindow和自定义一个菜单视图。但我建议你把图标放在左边,因为这是google的设计,是标准的。

        【讨论】: