2

I am a beginner of android,Kotlin, I don't know how to remove the top app bar in a specific and all activities. I have a splash screen and a new activity Below is my style's code,I already imported a material design in styles.xml I don't know what is the way to remove the top app bar in styles.xml

<resources>
    <!-- Base application theme. -->

    <style name="AppTheme" parent="Theme.MaterialComponents">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Android Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.shanjostech.newsample">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Main_Screen"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

2 Answers2

4

Add theme attribute to the activity where you want to hide appbar in manifest file

        <activity
            android:name="com.mvvm.Activity"
            android:label="@string/app_name"
            android:theme="@style/NewTheme">
        </activity>

then create a new theme in style.xml with parent as Theme.AppCompat.NoActionBar

 <style name="NewTheme" parent="Theme.AppCompat.NoActionBar">
    
   </style>
Wahdat Jan
  • 3,988
  • 3
  • 21
  • 46
2

This question is already answered here:-

How to remove it from all activities

How to remove it from specific activity

In Case if none of them work fine for you then try this:-

For specific activity,

Set theme in manifest file as mentioned below:-

<activity android:name=".activity.ContinueLoginActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait" />

Programmatically :-

Kotlin:

supportActionBar?.hide()

Java:

if (getSupportActionBar() != null) {
    getSupportActionBar().hide();
}

for remove it from all activities change .DarkActionBar by .NoActionBar in style.xml file:-

<resources>
<!-- 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>
PRANAV SINGH
  • 1,000
  • 11
  • 17