2012-12-20 32 views

回答

0

嘗試Override context menu colors in Android,看看是否有幫助。它說你不能重寫標準的上下文菜單選擇器,而是繼續爲長按上下文提供代碼。

爲主題的任何列表項我指定列表上的XML的背景下,如Android:背景=「@佈局/ CUSTOMSHAPE,custon形狀是一樣的東西:

<?xml version="1.0" encoding="UTF-8"?> 
<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<gradient android:startColor="@color/white" 
     android:endColor="@color/light_grey_background" 
     android:angle="270"/> 
<corners 
android:bottomRightRadius="7dp" 
android:bottomLeftRadius="7dp" 
android:topLeftRadius="7dp" 
android:topRightRadius="7dp"/> 
</shape> 

這是我從列表項調用喜歡的東西.XML:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:paddingTop="2dip" 
android:paddingBottom="2dip" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/customrecipeshape" 
    android:orientation="horizontal" > 

<ImageView 
    android:id="@+id/listicon" 
    android:layout_width="34px" 
    android:layout_height="wrap_content" 
    android:src="@drawable/icon_red" 
/> 
<TextView android:id="@+id/thing1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/black" 
    android:textAppearance="?android:attr/textAppearanceSmall"/>  


<TextView android:id="@+id/thing2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20px" 
     android:textColor="@color/grey21" 
     android:textAppearance="?android:attr/textAppearanceSmall"/> 
<TextView 
    android:id="@+id/thing3" 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/grey21" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    /> 




    </LinearLayout>  

而且這裏說:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/GY9DFX2H-Bc

您無法重寫自定義上下文菜單,但可以使用listview和alert對話框自己創建。