1

I realize this question is all over out here, but I have been unsuccessful in getting my app to work with devices using api >21. I have configured my app to use a material theme when api > 21 and use Theme.AppCompat.NoActionBar for everything lower than 21.

my styles in the values folder is...

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

    <!-- android: annotation is not needed in <=v21 -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorButtonNormal">@color/buttonNormal</item>

</style>

My styles in the values-v21 folder is...

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.NoActionBar">
        <!-- android: annotation is required in >=v21 -->
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
        <item name="android:colorButtonNormal">@color/buttonNormal</item>

    </style>
</resources>

My manifest

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

    <supports-screens
        android:anyDensity="true"
        android:requiresSmallestWidthDp="320"
        android:smallScreens="false"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".FinalScore"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".GameBoard"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".GamePlayOptions"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".GameSetup"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".HelpScreen"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="landscape">
        </activity>
    </application>
</manifest>

I am getting an error when trying to use the AlergDialog which I realize from my reading requires AppCompat or descendant

My AlertDialog

public void playAgainButton(View view){

        new AlertDialog.Builder(this)
                .setIcon(android.R.drawable.ic_dialog_info)
                .setTitle("Closing Activity")
                .setMessage("This will clear the board and return you to the Game Options screen.  Are you sure?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        playAgain();
                        //finish();
                    }

                })
                .setNegativeButton("No", null)
                .show();
    }

The error is... You need to use a Theme.AppCompat theme (or descendant) with this activity.

I'm not sure what piece it is I am missing so if anyone could point me in the right direction, I would greatly appreciate it.

Thanks,

bboursaw73
  • 1,128
  • 2
  • 13
  • 26
  • 4
    Possible duplicate of [How can I fix this error: You need to use a Theme.AppCompat theme (or descendant) with this activity](http://stackoverflow.com/questions/33474753/how-can-i-fix-this-error-you-need-to-use-a-theme-appcompat-theme-or-descendant) – Sathish Kumar J Jul 11 '16 at 05:02

1 Answers1

0

this is happening because you are using Theme.Material in style-21 xml... you should be use like this:

style.xml

<resources>
    <style name="AppTheme" parent="AppTheme.Base">

    </style>

    <!-- Base application theme. -->
    <style name="AppTheme.Base" 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>
        <item name="colorControlHighlight">@color/colorHighlight</item>
        <item name="android:windowBackground">@android:color/white</item>
    </style>
</resources>

and put this code in style-21.xml file

<resources>
    <style name="AppTheme" parent="AppTheme.Base">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>
Sagar Chavada
  • 5,169
  • 7
  • 40
  • 67