Why the Compilation error?
Because parameter in the setSupportActionBar(toolbar) is
android.support.v7.widget.Toolbar
and not the
android.widget.Toolbar
How to check it?
setSupportActionBar
is part of AppCompatActivity
. If you want to see the parameter then just override the method in your Activity and remove the import. It will indicate which class should be imported in order to get rid of the Compilation error.

What is the distinction?
It is pretty evident. Both are different classes one belongs to Support Library and the other does not.
Conjugation with AppCompatActivity
All the new features keep getting added in the Support libraries so that you will have the same functionality across all API levels. In other words, support libraries are updated constantly. For example, it is recommended to use android.support.v4.app.Fragment
with conjugation with AppcompatActivity.
So compatibility across all the API levels could be a reason.
Point being If your Activity extends AppCompatActivity then use
- android.support.v7.widget.Toolbar
- android.support.v4.app.Fragment
- android.support.v7.widget.RecyclerView etc