skip to Main Content

I’m a beginner in android studio and was trying to create my first project but Action bar is not visible in new Android Studio version. Please suggest some ways so that I can show the action bar in my android project.
All the elements are visible except the action bar.
I just want to show the action bar in my android project.

2

Answers


  1. You have to add it to your layout. This is the code for a general Toolbar. How you add it to your layout, depends on the root layout you use (CoordinatorLayout, FrameLayout, LinearLayout, …).

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/toolbarBackground">
    
        <com.google.android.material.appbar.MaterialToolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    
    </com.google.android.material.appbar.AppBarLayout>
    
    Login or Signup to reply.
  2. Please check if you are using the correct theme.

    Try with Theme.AppCompat.DayNight.DarkActionBar or similar themes with actionbar instead of your current theme. eg: Theme.AppCompat.Light.NoActionBar

    Kindly check your theme in themes.xml file, see the example below

    <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"/>

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search