The error:
You need to use a Theme.AppCompat theme (or descendant) with this activity
means that you need to use a style for the activity which is derived from AppCompat theme. It is usually in res/values/styles.xml
. If you don't have create it to something like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Then, use it for your activity by adding it to AndroidManifest.xml with android:theme="@style/AppTheme"
(please read the comment):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.testcode">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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>
<!-- Or you can use specific theme for the activity -->
<activity
android:name=".anotherActivity"
android:label="@string/app_name" >
android:theme="@style/AppTheme" >
</activity>
</application>
</manifest>