I am currently trying to create a popup menu when I click the menu button, as shown in the following screen:

I tried popupwindow methods but could not reach the exact case. This is how I try:
private View.OnClickListener showPopupWindow() { return new View.OnClickListener() { @Override public void onClick(View v) { PopupWindow popUp = popupWindowsort(); popUp.showAsDropDown(v, 1, 1); // show popup like dropdown list } }; } private PopupWindow popupWindowsort() { // initialize a pop up window type popupWindow = new PopupWindow(context); ArrayList<String> sortList = new ArrayList<String>(); sortList.add("VIEW FULL"); sortList.add("REPORT"); sortList.add("ADD TO LIST"); sortList.add("ADD TO CART"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.drop_down_line, sortList); // the drop down list is a list view ListView listViewSort = new ListView(context); // set our adapter and pass our pop up window contents listViewSort.setAdapter(adapter); // set on item selected listViewSort.setOnItemClickListener(onItemClickListener()); // some other visual settings for popup window popupWindow.setFocusable(true); popupWindow.setWidth(300); popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.background)); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); // set the listview as popup content popupWindow.setContentView(listViewSort); return popupWindow; } private AdapterView.OnItemClickListener onItemClickListener() { return new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (position == 0) { // adapter.notifyDataSetChanged(); } else if (position == 1) { report_lay.setVisibility(View.VISIBLE); // adapter.notifyDataSetChanged(); } else { // adapter.notifyDataSetChanged(); Log.i(TAG, "position2 " + position); } dismissPopup(); } }; } private void dismissPopup() { if (popupWindow != null) { popupWindow.dismiss(); } }
But I get the following result: 
and it also causes a problem in marshmallows.
How to create / create such a popup menu? Any help would be appreciated
android android-layout xml material-design
Sohail yasin
source share