setSupportActionBar toolbar cannot be applied to (android.widget.Toolbar) error
In your Activity.java
import android.support.v7.widget.Toolbar
instead of android.widget.Toolbar
:
import android.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
public class rutaActivity extends AppCompactActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ruta);
getSupportActionBar().hide();//Ocultar ActivityBar anterior
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar); //NO PROBLEM !!!!
Update:
If you are using androidx, replace
import android.support.v7.widget.Toolbar;
import android.support.v7.app.AppCompatActivity;
with newer imports
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.app.AppCompatActivity;
In using toolbar you should extends AppCompatActivity and
import android.support.v7.widget.Toolbar