2012-03-12 7 views
5

¿Cómo puedo crear un PopupMenu en android? Quiero un fondo gris y un icono antes del texto.Estilo PopupMenu Android

  • puedo arreglar esta dinámica en el código de java.
  • ¿Puedo arreglar esto con un archivo de estilo global?

así:

<style name="GreenText" parent="@android:style/PopupMenu"> 
    <item name="android:textColor">#00FF00</item> 
</style> 

o puedo construir un mejor PopupWindow como en este hilo?

inflate popup menu items programatically

Gracias.

Respuesta

2

no pude encontrar una manera fácil de diseñar mi PopupMenu, así que utilicé "PopupWindow" en su lugar, le pasé una vista de lista y lo puse como me gusta.

popView=layoutInflater.inflate(R.layout.pop_layout, null); // layout with a listview to  put in the popup window 
lv=(ListView)popView.findViewById(R.id.pop_listview); // then set listview parameters 

final PopupWindow contentsopupWindow = new PopupWindow(popView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
      contentsopupWindow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.pixel_dot));// set a background so the menu disappears when you click outside it 
      contentsopupWindow.setTouchable(true); 
      contentsopupWindow.setFocusable(true); 
      contentsopupWindow.setOutsideTouchable(true); 
      contentsopupWindow.setTouchInterceptor(new OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
         contentsopupWindow.dismiss(); 
         return true; 
         } 
         return false; 
         } 
      }); 
      WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 


      contentsopupWindow.showAsDropDown(anchorView); 
+0

y luego en el elemento de la lista, haga clic en use contentsopupWindow.dismiss(); para cerrar la ventana automáticamente –

Cuestiones relacionadas