这个问题在这里已有答案:
我在框架appcelerator中的noob,我在android中有一个简单的问题。我不知道怎么把Backbutton放在ActionBar中就像这个link image
此按钮不会出现在我看来。我用了重窗。 android sdk-version 27 SDK Titanium 7.0.0.GA
您可以像这样添加Action Bar:
<Alloy>
<Window title="Action Bar Title">
<ActionBar platform="android" displayHomeAsUp="true" onHomeIconItemSelected="close"></ActionBar>
</Window>
</Alloy>
您甚至可以添加字幕,菜单项,溢出菜单,图标甚至自定义视图。
阅读更多关于使用Action Bar in Titanium here的信息
为了更好地控制ActionBar以进行完全自定义,Titanium在SDK 6.2.0中引入了工具栏 - Read about Titanium Android Toolbar here
在onCreate中写下这个
{
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
覆盖onOptionsItemSelected方法
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
onBackPressed();
break;
}
}
return super.onOptionsItemSelected(item);
}