问题
I want to have kind of pop shown in the given images. What should use ? Pop window, dialog or alert dialog. i have tried all of these, but not able to match the exact UI.
回答1:
You can use Popup menu for this purpose.
Add this code in your 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();
}
});
In 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>
use this style in activity theme as :
<item name="popupMenuStyle">@style/MyPopupMenu</item>
来源:https://stackoverflow.com/questions/48048001/how-to-get-such-kind-of-dialog