Search code examples
androidxmlandroid-actionbar

I have removed the action bar for a specific activity and it is still showing in the preview


I have removed the action bar for a specific activity and it is working perfectly and the action bar is removed when I run the app on Emulator/Device but the problem is that it is still showing in the preview. Due which It affects my design.

Here is my style file where I set the noAction bar:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    </style>


    <!-- Text Styles -->
    <style name="textStyle">
        <item name="android:textColor">@color/theme_color</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="textStyle.tagline">
        <item name="android:textAllCaps">true</item>
        <item name="android:textSize">46sp</item>
    </style>


    <!-- Button Styles -->
    <style name="button_transparent">
        <item name="android:textAllCaps">true</item>
        <item name="android:textColor">@color/theme_color</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="button_blue">
        <item name="android:textAllCaps">true</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>


</resources>

I have also applied that style on activities as shown here:

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

    <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=".Splash_Screen" android:theme="@style/AppTheme.NoActionBar"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".protips_activity" android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

But is still showing in the preview as shown here: Android Studio preview


Solution

  • Fastest solution:

    1. Open your activity's XML.
    2. Switch to the design tab.
    3. On the upper part of the design tab click on AppTheme.
    4. Choose your new theme (the one with no action bar).

    However

    Adding this line to the activity XML root view should automatically reference to the same activity theme set in AndroidManifest

    tools:context=".YourActivityName"