Reputation: 27
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.
Upvotes: 0
Views: 5094
Reputation: 21
Create this theme in themes.xml
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Call in Manifest.xml
<activity
android:name=".ui.activities.SplashScreen"
android:exported="true"
android:theme="@style/NoActionBarTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0
Reputation: 364948
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>
Upvotes: 3
Reputation: 33
If my understanding is correct you don't want action bar any more.then if you are using old base android theme then you can change into this.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
or if you using new material design then you can change into.
<!-- Base application theme. -->
<style name="Theme.TextOverlayDemo" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
Thank you, feel free to ask doubts.
Upvotes: 0