Android : Get view Reference to a Menu Item

前端 未结 6 719
醉酒成梦
醉酒成梦 2020-11-27 05:19

I plan to use quick actions UI pattern in my application. Android Quick Actions UI Pattern . The quick action window needs a pivot view to stick to.

    qui         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 05:52

    You can achieve this by providing your menu item with an actionViewClass property in xml and then you will be able to get the pivot view u wanted. The code would be something like this

    
    

    In your OnCreateOptionsMenu do this

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu_search, menu);
        locButton = (ImageButton) menu.findItem(R.id.menu_find).getActionView();
        locButton.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                createPopup();
                mQuickAction.show(v);
            }
        });
        return true;
    }
    

提交回复
热议问题