Search code examples
androidandroid-actionbarandroid-appcompat

How to hide Action Bar in Android Studio 4.1?


I am using Android Studio 4.1 and I want to hide the Action Bar. I searched stack overflow, but it seems there are some new methods introduced in Android Studio update of October 2020 since getActionBar().hide(); line method no longer works and app directly crashes. For more clarity, I created a new Project and added nothing else except the getActionBar().hide(); in the onCreate() method. Still the app crashes. My emulator is running on API 30, Android 11 on Pixel 3.

Kindly help.


Solution

  • It doesn't depend by Android Studio.
    Since you are using a AppCompatActivity and you have to use getSupportActionBar() instead of getActionBar().

    As alternative you can use a .NoActionBar theme, for example.

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
       ...
    </style>