Android: Theme ContextMenu item selection

时间秒杀一切 提交于 2019-12-06 11:10:06
ialexander

Try Override context menu colors in Android and see if it helps. It says you can't override the standard context menu selector but goes on to give code for context on long-press.

To theme any list item I assign a background on the lists xml, such as android:background="@layout/customshape, custon shape being something like:

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

Which I call from the list item .xml with something like:

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

And as stated here: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/GY9DFX2H-Bc

You can't override the custom context menu, but you can make your own using a listview and an alert dialog.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!