title: Creating a custom popup dialog menu
body: <p>I'm currently trying to achieve popup menu on menu button click as shown in following screen:</p>
  <p><a href="https://i.stack.imgur.com/XLy2Y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XLy2Y.jpg" alt="enter image description here" /></a></p>
  <p>I tried popupwindow methods but couldn't achieve the exact case.
  This is how I'm trying:</p>
  <pre><code>   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&lt;String&gt; sortList = new ArrayList&lt;String&gt;();
      sortList.add(&quot;VIEW FULL&quot;);
      sortList.add(&quot;REPORT&quot;);
      sortList.add(&quot;ADD TO LIST&quot;);
      sortList.add(&quot;ADD TO CART&quot;);
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(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, &quot;position2 &quot; + position);
              }
              dismissPopup();
          }
      };
  }
  
  private void dismissPopup() {
      if (popupWindow != null) {
          popupWindow.dismiss();
      }
  }
  </code></pre>
  <p>But I'm getting the following result:
  <a href="https://i.stack.imgur.com/hs5Ne.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hs5Ne.png" alt="enter image description here" /></a></p>
  <p>and this is also causing a problem in marshmallow.</p>
  <p>How do I create such popup menu?</p>