Search code examples
androidandroid-studioandroid-toolbarandroid-appcompatandroidx

Which dependencies are needed for using the Toolbar?


I'm trying to create a Navigation Drawer. For that I need to use a toolbar. I have the following dependencies:

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'

And in my layout xml I have:

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/primaryColor"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

In my Java:

import androidx.appcompat.widget.Toolbar;

public class TestMenu extends AppCompatActivity {
    private ToolBar toolBar;

And I get the following error when I try to build:

error: cannot find symbol
    private ToolBar toolBar;
            ^
  symbol:   class ToolBar

Also Android Studio says:

enter image description here

Which dependencies am I missing?


Solution

  • import androidx.appcompat.widget.Toolbar;
    
    public class TestMenu extends AppCompatActivity {
        private ToolBar toolBar;  // here  
    

    Replace "ToolBar" with "Toolbar"