5

の変化幅を持っていますこの方法:アンドロイド:現在、私は、デフォルトの幅を有するオーバーフローメニューをオーバーフローメニュー

<style name="MyWorkspaceDetailTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> 

     <item name="android:popupMenuStyle">@style/MyPopupMenu</item> 

</style> 

<style name="MyPopupMenu" parent="@android:style/Widget.Holo.ListPopupWindow"> 
    <item name="android:dropDownWidth">30dp</item> 


</style> 

しかしdidn何の成功もありません。誰でも助けてください。

答えて

0

私は[http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html]チュートリアルこれをfollwingましたが、それはので、私はまた同じ答えを探していたし、しばらく探して幅

を変更する方法については言及しなかった、StackOverflowの上のすべての質問が未回答でした。最後に、方法を見つけるためにdeveloper.google.comを掘り下げなければなりませんでした。

http://developer.android.com/reference/android/widget/ListPopupWindow.html

あなたは実際に私たちの作業を行う方法のsetContentWidth(int型の幅)を見つけます。ここで

この==>

enter image description here

への答え

 //.......... Something on top 
     popupMenu.show(); 

     // Try to force some horizontal offset 
     try { 
      Field fListPopup = menuHelper.getClass().getDeclaredField("mPopup"); 
      fListPopup.setAccessible(true); 
      Object listPopup = fListPopup.get(menuHelper); 
      argTypes = new Class[] { int.class }; 
      Class listPopupClass = listPopup.getClass(); 

      // Get the width of the popup window 
      int width = (Integer) listPopupClass.getDeclaredMethod("getWidth").invoke(listPopup); 

      // Invoke setHorizontalOffset() with the negative width to move left by that distance 
      listPopupClass.getDeclaredMethod("setHorizontalOffset", argTypes).invoke(listPopup, -width); 
/*********** THIS LINE DOSE OUR WORK and increases the width of OverFlow Menu ******/ 
      listPopupClass.getDeclaredMethod("setContentWidth", argTypes).invoke(listPopup, width+200); 

      // Invoke show() to update the window's position 
      listPopupClass.getDeclaredMethod("show").invoke(listPopup); 
     } catch (Exception e) { 
      // Again, an exception here indicates a programming error rather than an exceptional condition 
      // at runtime 
      Log.w("Soemthing", "Unable to force offset", e); 
     } 

enter image description here

です

関連する問題