0

enter image description here

How to remove the excess whitespace in pop menu selection? Is there any way i can remove it. I read some article here and tried the code. But its not working for me.

    final Button btnwallet = findViewById(R.id.btn_wallet);
    btnwallet.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
        @Override
        public void onClick(View v) {
            PopupMenu popupMenuWallet = new PopupMenu( MainActivity.this, v, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0 );

            popupMenuWallet.getMenuInflater().inflate(R.menu.menu_wallet, popupMenuWallet.getMenu());

            popupMenuWallet.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    int idwallet = item.getItemId();
                    switch (idwallet){
                        case R.id.menu_wallet1:

                            return  true;
                        case R.id.menu_wallet2:

                            return  true;

                        default:

                        return MainActivity.super.onOptionsItemSelected(item);
                    }
                }
            });
            popupMenuWallet.show();
        }
    });
No Name
  • 392
  • 1
  • 4
  • 18
  • 1
    Possible duplicate of [Android custom dropdown/popup menu](https://stackoverflow.com/questions/21329132/android-custom-dropdown-popup-menu) – Milan Pansuriya Dec 06 '18 at 06:13

1 Answers1

0

i already find answer to my problem by using this code. It remove excess whitespace in menu item. I post it here because so anyone can also use this code that same with my problem.

    rlNews = findViewById(R.id.rl_news);

    btnNews = findViewById(R.id.btn_news);
    btnNews.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            layoutInflaterNews = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);

            View containerNews = (View) layoutInflaterNews.inflate(R.layout.list_item_news, null);

            popupWindowNews = new PopupWindow(containerNews, 290, 330, true);
            popupWindowNews.showAsDropDown(btnNews,0,0);

            containerNews.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                popupWindowNews.dismiss();

                return true;
                }
            });
        }
    });
No Name
  • 392
  • 1
  • 4
  • 18