【发布时间】:2014-10-14 19:52:41
【问题描述】:
我只是使用 AppCompact v7 中的支持操作栏。我写了 bar.setDisplayHomeAsUpEnabled(true) 并想听这个按钮,但在监听器中:
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();
switch (id) {
case R.id.action_settings:
return true;
case R.id.HomeAsUp:
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
当我想从它的 id 中查找项目时,方法不返回任何内容。如何使用支持操作栏收听此按钮?
【问题讨论】:
-
代替 R.id.HomeAsUp,试试 android.id.R.home
-
谢谢。这可行,但是 HomeAsUp 按钮呢?
-
我从未将 HomeAsUp 视为有效的 android.R.id...这是您自己创建的 id 吗?
-
不,当我选择 R.id -> 它有 HomeAsUp。据我了解,它是带箭头的主页按钮。我曾认为,这两个不同的按钮。
标签: android android-actionbar-compat