android设备上的自定义操作图标

android设备上的自定义操作图标,android,android-layout,user-interface,android-ui,Android,Android Layout,User Interface,Android Ui,我通过调用action layout来开发自定义菜单项,但当我录制该动作菜单时,按color并没有应用总高度,从而提供一些上下边距 下面是我的代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:

我通过调用action layout来开发自定义菜单项,但当我录制该动作菜单时,按color并没有应用总高度,从而提供一些上下边距

下面是我的代码:

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

    <ImageView 
        android:minWidth="56dp"
        android:id="@+id/voicemailNotificationCounter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"
        android:clickable="true"
        android:background="@drawable/ab_pressedicon_bgcolor"
        android:contentDescription="@string/voicemailnotification"
        android:src="@drawable/ab_voicemail"> 
     </ImageView>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/vmNotificationTextCounter"
        android:text="1"
        android:visibility="visible"
        android:layout_alignRight="@+id/voicemailNotificationCounter"
        android:layout_marginRight="10dp"
        android:gravity="center"
        android:textColor="#fff"
        android:includeFontPadding="false"
        android:background="@drawable/notification_alertbg"
        android:textSize="12sp"/>

</RelativeLayout> 

部分问题在于您没有使用ImageButton

将图像与文本与ImageButton组合。您甚至可以独立调整ImageButton中的文本和图像


希望一个ImageButton能在动作菜单中工作,我还没有实际测试过那个部分

你的图标是九块补丁吗?不是,它不是九块补丁图像,它只是普通的操作栏图标。@Rayani,顺便说一下,如果你发现一个对你最有用的答案,将其标记为接受也是一种表示感谢的好方法。请参阅:此外,不要低估9-patch的使用,即使您发现它通常不在操作菜单中使用。使用带有match_parent的9-patch和现有代码中的一些调整可能也会起作用(不需要ImageButton)。