How to add overflow menu to Toolbar?

前端 未结 3 829
粉色の甜心
粉色の甜心 2020-12-09 16:09

I\'m trying to use Android ActionBar in my app, and have an option that\'s hidden away in the overflow menu.

There\'s a lot of documentation out there,

3条回答
  •  甜味超标
    2020-12-09 16:59

    Simple do This copy this code on your MainActivet`

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main2, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                Group gp=(Group)findViewById(R.id.order);
    
                return true;
            }
    
            return super.onOptionsItemSelected(item);
        }`
    

    Now Make Directory file for menu name for this go on Android_Studio->app Folder->Right_Click->New->Directory-> Enter name menu now Create a xml file in there with menu2.xml name

    and past this code on menu2.xml file

        
    
        
    
    
    

    if any Query Please text me

提交回复
热议问题