Action Bar icon as up enabled not the title

后端 未结 4 987
逝去的感伤
逝去的感伤 2021-02-04 15:43

How to make app icon as up enabled in actionbarsherlock (not the title only icon) like in whats app.

4条回答
  •  失恋的感觉
    2021-02-04 16:17

    Add the following to your onCreate method:

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    

    and define the following override method in your activity:

    @Override
    public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            break;
        default:
            return super.onOptionsItemSelected(item);
        }
        return true;
    }
    

提交回复
热议问题