Search code examples
androidperformanceandroid-studioruntime-errorlogcat

Error You need to use a Theme.AppCompat theme (or descendant) with activity


I am working on anroid application, as it run fine with dark action bar but when I change this to no action bar the app crashes and show me this error in logcat.

Logcat Error

I have make changes with the style and xml file but remains same issue. As I again ad Dark action bar it start working fine.

the links I have studied

Link1

Here is my style file

<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">@color/colorText</item>
    <item name="android:textColorHint">@color/colorText</item>
    <item name="colorControlNormal">@color/colorText</item>
    <item name="colorControlActivated">@color/colorText</item>
</style>

<resources>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Here is the manifest file

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".activities.SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activities.WelcomeActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.LoginActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.RegisterActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.UsersListActivity"
        android:screenOrientation="portrait" />
</application>


Solution

  • Solution is change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is, a non Theme.AppCompat value

    In your case issue is with your manifest file you haven't specified android:theme="@style/AppTheme.NoActionBar" inside activities tag

    Go your manifest file and replace splash activity with this:

    <activity
                android:name=".activities.SplashActivity"
                android:theme="@style/AppTheme.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    

    Inside your splash activity class do this:

    public class SplashActivity extends AppCompatActivity