我需要使用左侧按钮项创建ActionBar
,如下图所示。我尝试使用大量的代码,但我仍然没有得到任何东西。请帮我用按钮创建android ActionBar
。
我需要创建如下 Image
注意:我没有示例代码,而且这不合适,因为我是Android的新开发人员。
答案 0 :(得分:1)
添加操作按钮在您的活动中添加此内容
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//and this to handle actions
@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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
并在菜单目录
下的main.xml中<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:icon="@drawable/icon"
android:orderInCategory="100"
app:showAsAction="always" />
要获取左侧的图标,请参阅this