toolbar back button click android

toolbar back button click android

XML

   <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar_order"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        app:navigationIcon="@drawable/back_arrow"
        android:theme="?attr/actionBarTheme" >
</androidx.appcompat.widget.Toolbar>


Java Code :


Inside onCreate 
  Toolbar toolbar = findViewById(R.id.toolbar_order);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Order Details");




Outside onCreate

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }