工具栏DisplayHomeAsUp Btn id

时间:2015-05-13 22:13:35

标签: android

我的活动中的HomeAsUp按钮有一个微不足道的问题,它不是正在执行或更简洁的我不会检查它是不正确的,所以我必须询问,它的HomeAsUp的id是什么工具栏上的按钮?

我的代码:

public boolean onOptionsItemSelected(MenuItem item) {
    log.d("item i "+item.getItemId());
    log.d("Home id "+android.support.v7.appcompat.R.id.home);
    log.d("Home id from R "+R.id.home);
    log.d("Home id from R "+R.id.homeAsUp);
    if (item.getItemId() == R.id.a_profile_menu_item_edit) {
        showProfileEdit();
        return true;
    } else if (item.getItemId() == android.support.v7.appcompat.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}  

根据这些日志我打印这是他们打印的内容:

D/Profile[onOptionsItemSelected] - 121﹕ item id 16908332
D/Profile[onOptionsItemSelected] - 122﹕ Home id 2131492868
D/Profile[onOptionsItemSelected] - 123﹕ Home id from R 2131492868
D/Profile[onOptionsItemSelected] - 124﹕ Home id from R 2131492877

所以我的item.id是16908332,但是R.id.home,R.id.homeAsUp,android.support.v7.appcompat.R.id.home都不是正确的,感谢任何帮助... < / p>

1 个答案:

答案 0 :(得分:2)

你需要 android .R.id.home,ID为16908332。 注意前缀中的 android

相关问题