android.R.id.home 找不到符号
android.R.id.home can not find symbol
我在 AppCompat 库中使用了 Toolbar 组件而不是 Default Actionbar。
编译时间:我得到找不到符号的编译错误android.R.id.home
public void setupActionBar() {
// Set a Toolbar to replace the ActionBar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_help) {
showHelp();
return true;
}else if(id == android.R.id.home){
Log.d(TAG, "Back Button clicked!");
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
将此添加到您的 activity。
@Override
public void onBackPressed() {
// your code.
this.finish();
}
android.R.id.home 是在 API 级别 11 中引入的。
这里有更多细节:
我在 AppCompat 库中使用了 Toolbar 组件而不是 Default Actionbar。
编译时间:我得到找不到符号的编译错误android.R.id.home
public void setupActionBar() {
// Set a Toolbar to replace the ActionBar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_help) {
showHelp();
return true;
}else if(id == android.R.id.home){
Log.d(TAG, "Back Button clicked!");
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
将此添加到您的 activity。
@Override
public void onBackPressed() {
// your code.
this.finish();
}
android.R.id.home 是在 API 级别 11 中引入的。 这里有更多细节: