Android : Get view Reference to a Menu Item

前端 未结 6 724
醉酒成梦
醉酒成梦 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:35

    Inorder to get reference Views of menu items we need to do this,

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.section, menu);
    
        new Handler().post(new Runnable() {
            @Override
            public void run() {
    
                final View menuItemView = findViewById(R.id.action_preview);
                // SOME OF YOUR TASK AFTER GETTING VIEW REFERENCE
    
            }
        });
    
    
        return true;
    }
    

提交回复
热议问题