我想在操作栏右侧添加一个按钮,就像这个屏幕截图中的示例一样:
我在 onCreate 方法中获取 actionBar:
![a screenshot of an actionbar with no buttons. the title is 'Example'](https://istack.dev59.com/Xesrl.webp)
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
并在onOptionsItemSelected方法中添加返回按钮代码,如下所示:
public boolean onOptionsItemSelected(MenuItem item){
Intent myIntent = new Intent(getApplicationContext(),MainActivity.class);
startActivityForResult(myIntent, 0);
return true;
}
我该如何添加按钮?