2012-03-12 4 views
5

どのように私はアンドロイドでPopupMenuをスタイルするのですか?私はテキストの前に灰色の背景とアイコンが欲しい。スタイルPopupMenu Android

  • この動的コードをJavaコードで修正できますか?
  • これをグローバルスタイルファイルで修正しますか?

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

    または私はより良いこのスレッドのようにPopupWindowを構築することができます。このような

inflate popup menu items programatically

ありがとうございます。

答えて

2

PopupMenuのスタイルを簡単に見つけることができず、代わりに "PopupWindow"を使用し、リストビューを渡して、必要に応じてスタイルを設定します。

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

次にリストアイテムをクリックしてくださいuseopopWindow.dismiss();自動的にウィンドウを閉じる –

関連する問題