2015-08-01 21 views

Odpowiedz

40

To nie jest widżet. Jest to ImageButton (bez obramowania w stylu) za pomocą ikony przelewowy, który obejmuje PopupMenu

na wizyty samouczka dokumentacja http://developer.android.com/guide/topics/ui/menus.html#PopupMenu

Odnosi się ładnym fragment kodu z linku powyżej:

<ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_overflow_holo_dark" 
     android:contentDescription="@string/descr_overflow_button" 
     android:onClick="showPopup" /> 

Następnie użyj, aby wyświetlić wyskakujące okienko:

public void showPopup(View v) { 
    PopupMenu popup = new PopupMenu(this, v); 
    MenuInflater inflater = popup.getMenuInflater(); 
    inflater.inflate(R.menu.actions, popup.getMenu()); 
    popup.show(); 
} 

I Roman Nurik również to świetnie l, aby uzyskać dowolny materiał ikonę projektowania chcesz:

http://romannurik.github.io/AndroidAssetStudio/

a obraz jest dostępny pod adresem:

http://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html#source.type=clipart&source.clipart=more_vert&source.space.trim=0&source.space.pad=0&name=ic_action_more_vert&theme=light&color=rgba(33%2C%20150%2C%20243%2C%200.6)

+0

dodany link do właściwego użyciu tego narzędzia powyżej @Cristian –

+0

@Laurent patrz UPDATE –

0

Jak znalazłem w internecie, to nazywa się „ikoną przelewowym "lub przepełnienie działania".

Ten kod może ci pomóc. (Kod wynosi there)

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@+id/menu_red" 
     android:orderInCategory="1" 
     android:showAsAction="never" 
     android:title="@string/red_string"/> 
    <item 
     android:id="@+id/menu_green" 
     android:orderInCategory="2" 
     android:showAsAction="never" 
     android:title="@string/green_string"/> 
</menu> 
3

"pierwotnym" widget trzy kropki jest android.widget.ActionMenuPresenter.OverflowMenuButton (ActionMenuPresenter.java). Niestety jest to klasa prywatna. Tu pracuje krótsza wersja:

public class OverflowMenuButton extends AppCompatImageView 
{ 
    public OverflowMenuButton(Context context) 
    { 
     this(context, null); 
    } 

    public OverflowMenuButton(Context context, AttributeSet attrs) 
    { 
     this(context, attrs, 0); 
    } 

    public OverflowMenuButton(Context context, AttributeSet attrs, int defStyleAttr) 
    { 
     super(new ContextThemeWrapper(context, R.style.OverflowButtonTheme), attrs, R.attr.actionOverflowButtonStyle); 

     setClickable(true); 
     setFocusable(true); 
     setVisibility(VISIBLE); 
     setEnabled(true); 
    } 
} 

tematów ContextThemeWrapper uzyskać ciemne i jasne wersję:

<!--White dots theme--> 
<style name="OverflowButtonTheme" parent="@style/Theme.AppCompat"> 
    <item name="actionOverflowButtonStyle">@style/Widget.AppCompat.ActionButton.Overflow</item> 
</style> 

<!--Dark dots theme--> 
<style name="OverflowButtonThemeLight" parent="@style/Theme.AppCompat.Light"> 
    <item name="actionOverflowButtonStyle">@style/Widget.AppCompat.Light.ActionButton.Overflow</item> 
</style> 
18

Możesz także po prostu użycie ImageButton z atrybutem actionOverflowButtonStyle stylu.

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="?android:attr/actionOverflowButtonStyle"/> 
1
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="24dp" 
    android:height="24dp" 
    android:viewportWidth="24.0" 
    android:viewportHeight="24.0"> 
    <path 
     android:fillColor="#FF000000" 
     android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zm0,2c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zm0,6c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/> 
</vector> 
+0

eleganckie rozwiązanie - dzięki – gnB