9

当我使用 Actionbarsherlock

public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case android.R.id.home:
        this.finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

我注意到 android.R.id.home 来自 API 11。我们如何确保 android.R.id.home 在 API 8 上是正确的?


它是一个静态的最终常量,这意味着它的值被复制到编译后的代码中,而不仅仅是一个引用。这就是为什么它能够在每个 API 级别上成功使用的原因。

4

1 回答 1

8

It is a static final constant which means its value is copied into the compiled code instead of being just a reference. This is why it is able to be used successfully on every API level.

于 2012-10-12T14:48:53.667 回答