Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between android.widget.Toolbar and android.support.v7.widget.Toolbar?

Tags:

Could someone please explain to me the difference between them and why aren't they interchangeable?

Importing android.widget.Toolbar will cause compilation error whereas importing android.support.v7.widget.Toolbar works perfectly fine.

What's the distinction between these two imports?

import android.widget.Toolbar;

...

Toolbar toolbar = findViewById(R.id.app_bar);

setSupportActionBar(toolbar);

import android.support.v7.widget.Toolbar;

...

Toolbar toolbar = findViewById(R.id.app_bar);

setSupportActionBar(toolbar);
like image 885
Ong Jin Bin Avatar asked Apr 03 '19 09:04

Ong Jin Bin


1 Answers

The support library (now AndroidX) is designed for backwards compatibility while android.widget.Toolbar is the current plattform type.
If you don't know what the support library is take a look at this answer.
By default Android Studio makes you use AppCompatActivity which is part of the support library and thusly expects a support toolbar as well.

like image 97
Vringar Avatar answered Oct 15 '22 09:10

Vringar