答案 0 :(得分:1)
您可以将Popup menu用于此目的。
在您的activity.java中添加此代码:
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(HomeActivity.this, fab);
popup.getMenuInflater().inflate(R.menu.menu_home, popup.getMenu());
popup.setGravity(Gravity.END);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
// your action
default:
return true;
}
}
});
popup.show();
}
});
在style.xml
<style name="MyPopupMenu" parent="@style/Widget.AppCompat.PopupMenu.Overflow">
<item name="fontPath">Muli_Regular.ttf</item>
<item name="android:dropDownHorizontalOffset">0dp</item>
<item name="android:dropDownVerticalOffset">57dp</item>
</style>
在活动主题中使用此样式:
<item name="popupMenuStyle">@style/MyPopupMenu</item>