Toolbar button click event functionality

后端 未结 3 667
醉话见心
醉话见心 2021-01-29 16:35

I have created settings button in Toolbar, now I need to navigate the screen to settings screen, when ever i click the settings button.

3条回答
  •  我在风中等你
    2021-01-29 16:51

    Try 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.your_menu_xml, menu);
            return true;
        }
    
     public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()){
                case R.id.action_settings:
                    //Strar activity here
                    break;
                default:
                    return super.onOptionsItemSelected(item);
            }
            return super.onOptionsItemSelected(item);
        }
    

提交回复
热议问题