Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.R.id.home can not find symbol

I used Toolbar component in AppCompat library instead of Default Actionbar.

Compile time: I get compile-error that cannot find symbol 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);
}
like image 994
mohamad mohsen Taheri Avatar asked Oct 19 '22 18:10

mohamad mohsen Taheri


1 Answers

android.R.id.home was introduced in API level 11. here is more detail: https://stackoverflow.com/a/18719090/2178694

like image 117
hr.Astian Avatar answered Oct 21 '22 17:10

hr.Astian