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;
How to resolve the Android error method setSupportActionBar in class AppCompatActivity cannot be applied to given types?
First of all appcompat 23.0.3 doesn't exist.
Use 23.0.1
com.android.support:appcompat-v7:23.0.1
Then the method setSupportActionBar
works with android.support.v7.widget.Toolbar
.
Check the import in your code.
When you are using the Toolbar
,you have to use the right import:
import android.support.v7.widget.Toolbar;
Finally also in your layout, you have to use the right widget.
<android.support.v7.widget.Toolbar
..... />
setSupportActionBar cannot be applied to android.support.v7.widget.Toolbar
Looks like it's a typo, and you're calling getSupportActionBar()
(with a g
) instead of setSupportActionBar()
.
setSupportActionBar in AppCompactActivity cannot be applied android
All the v7 libraries are used to support devices with old android versions. If you want to provide a the support use import android.support.v7.widget.Toolbar
with setSupportActionBar()
Otherwise as in your case you have import android.widget.Toolbar;
so use setActionBar()
instead.
Toolbar error on Java android studio application
In java activity file remove the the Toolbar from android.widget
package
import android.widget.Toolbar;
And add androidx Toolbar from androidx.appcompat.widget
package instead
import androidx.appcompat.widget.Toolbar;
setSupportActionBar cannot be applied
You need to change your import from,
import android.widget.Toolbar;
to
import android.support.v7.widget.Toolbar;
or
In Androidx
you can use
import androidx.appcompat.widget.Toolbar;
This will surely solve the problem.
Related Topics
How to Enable and Disable a Component
Send Request Over Wifi (Without Connection) Even If Mobile Data Is on (With Connection) on Android M
How to Rotate Textview 90 Degrees and Display
Install App via Usb: the Device Is Temporarily Restricted
Android Studio: Default Project Directory
How to Handle System_Alert_Window Permission Not Being Auto-Granted on Some Pre-Marshmallow Devices
Cannot Create an Instance of Class Viewmodel
How to Know If a Fragment Is Visible
Retrofit2: Modifying Request Body in Okhttp Interceptor
Map Markers with Text in Google Maps Android API V2
Moving from One Activity to Another Activity in Android
Why Is Listview.Getcheckeditempositions() Not Returning Correct Values
Picasso Load Drawable Resources from Their Uri
Syncing Android Studio Project with Gradle Files
Android: Google Maps Location with Low Battery Usage
Change Date String Format in Android
How to Reduce the Spacing Between the Action Item Icons on Action Bar