What's the name of the little widget with three dots inside a cardview in android?

后端 未结 5 1224
滥情空心
滥情空心 2021-01-30 16:55

What\'s the little widget with three dots? How can I add it to my app?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 17:09

    The "original" three dot widget is the android.widget.ActionMenuPresenter.OverflowMenuButton (ActionMenuPresenter.java). Sadly it is a private class. Here a working shorter version:

    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);
        }
    }
    

    Themes of the ContextThemeWrapper to get a dark and light version:

    
    
    
    
    
    

提交回复
热议问题