Toolbar navigation icon never set Toolbar navigation icon never set android android

Toolbar navigation icon never set


Currently you can use it, changing the order: (it seems to be a bug)

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);setSupportActionBar(toolbar);toolbar.setNavigationIcon(R.drawable.ic_good);toolbar.setTitle("Title");toolbar.setSubtitle("Sub");toolbar.setLogo(R.drawable.ic_launcher);


Specific to the navigation icon, this is the correct order

// get the actionbar as Toolbar and set it upToolbar toolbar = (Toolbar) findViewById(R.id.signIn_toolbar);setSupportActionBar(toolbar);

Inform the Toolbar to provide back navigation. This will set the icon to the default material icon

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Later override the icon with the custom one, in my case the Holo back icon

toolbar.setNavigationIcon(R.drawable.ic_chevron_left_white_36dp);


(The answer to user802421)

private void setToolbar() {    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);    if (toolbar != null) {        setSupportActionBar(toolbar);        toolbar.setNavigationIcon(R.drawable.ic_action_back);        toolbar.setNavigationOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                onBackPressed();            }        });    }}

toolbar.xml

<android.support.v7.widget.Toolbar    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/toolbar"    android:layout_width="match_parent"    android:layout_height="@dimen/toolbar_height"    android:background="?attr/colorPrimaryDark" />