5

Hiện nay tôi có một thực đơn tràn trong đó có chiều rộng mặc định:Android: thay đổi chiều rộng của menu tràn

enter image description here

Những gì tôi muốn là:

enter image description here

Tôi đã cố gắng thay đổi chủ đề theo cách này:

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

nhưng didn không thành công. Xin vui lòng bất cứ ai có thể giúp đỡ.

Trả lời

0

Tôi đã follwing này [http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html] hướng dẫn, nhưng nó đã không đề cập cách để thay đổi chiều rộng

Vì vậy, tôi cũng đang tìm kiếm câu trả lời tương tự và đang tìm kiếm thời gian, tất cả những câu hỏi trên Stackoverflow đã được trả lời. Cuối cùng tôi phải đào tạo developer.google.com để tìm ra cách.

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

bạn sẽ tìm thấy một phương pháp setContentWidth (int width) mà thực sự làm việc của chúng tôi.

Dưới đây là câu trả lời

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

Để == này>

enter image description here

Các vấn đề liên quan