public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.option_menu);
toolbar.setOnMenuItemClickListener(new MyMenuItemClickListener());
class MyMenuItemClickListener implements Toolbar.OnMenuItemClickListener {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.scan:
Toast.makeText(MainActivity.this, "你点击了(我的好友)",
Toast.LENGTH_SHORT).show();
return true;
case R.id.discoverable:
Toast.makeText(MainActivity.this, "你点击了(设置在线)",
Toast.LENGTH_SHORT).show();
return true;
case R.id.back:
finish();
System.exit(0);
return true;
}
return false;
}
}
}
}