How to enable homeAsUp or call setDisplayHomeAsUpEnabled() on standalone toolbar with appcompat v21

@Pedro Oliveira’s solution worked. I could even find the drawable that the AppCompat library uses (and therefore is already included in the apk). What more it’s also mirrored, so it works both for ltr, rtl locales:

actionbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

and this is it alltogether, with the correction from @VictorYakunin

public class SettingsActivity extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        Toolbar actionbar = (Toolbar) findViewById(R.id.actionbar);
        if (null != actionbar) {
            actionbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

            actionbar.setTitle(R.string.title_activity_settings);
            actionbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    NavUtils.navigateUpFromSameTask(SettingsActivity.this);
                }
            });

            // Inflate a menu to be displayed in the toolbar
            actionbar.inflateMenu(R.menu.settings);
        }
    }
}

Leave a Comment