5

Derzeit ich ein Überlaufmenü haben, die Standardbreite hat:Android: Änderungsbreite des Überlaufmenü

enter image description here

Was ich will, ist:

enter image description here

Ich habe versucht, das Thema zu ändern auf diese Weise:

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

aber didn Ich habe keinen Erfolg. Bitte kann jemand helfen.

Antwort

0

Ich war follwing dieses [http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html] Tutorial, aber es hat nicht Art und Weise Breite zu ändern erwähnen

i gleiche Antwort So auch während der Suche gesucht und sind, alle Fragen auf Stackoverflow war unbeantwortet. Schließlich musste ich den developer.google.com ausgraben, um einen Weg zu finden.

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

Sie eine Methode setContentWidth finden (int Breite), die eigentlich unsere Arbeit erledigt. Hier

ist die Antwort

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

Zu diesem ==>

enter image description here

Verwandte Themen