Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix: "You need to use a Theme.AppCompat theme (or descendant) with this activity"

I am having trouble running my Android app in a fullscreen mode per instructions of a video. When it tries to run, the app crashes with the error.

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

Manifest File

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.djsg38.hikerswatch">  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" />  <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"         android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >         <intent-filter>             <action android:name="android.intent.action.MAIN" />              <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>     </activity> </application>  </manifest> 

Styles File

<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> 

Partial MainActivity that may be useful

public class MainActivity extends AppCompatActivity { 
like image 300
Doug Steiert Avatar asked Sep 20 '16 22:09

Doug Steiert


1 Answers

Your application has an AppCompat theme

<application     android:theme="@style/AppTheme"> 

But, you overwrote the Activity (which extends AppCompatActivity) with a theme that isn't descendant of an AppCompat theme

<activity android:name=".MainActivity"     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 

You could define your own fullscreen theme like so (notice AppCompat in the parent=)

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:windowNoTitle">true</item>     <item name="android:windowActionBar">false</item>     <item name="android:windowFullscreen">true</item>     <item name="android:windowContentOverlay">@null</item> </style> 

Then set that on the Activity.

<activity android:name=".MainActivity"     android:theme="@style/AppFullScreenTheme" > 

Note: There might be an AppCompat theme that's already full screen, but don't know immediately

like image 160
OneCricketeer Avatar answered Oct 05 '22 09:10

OneCricketeer