Reputation: 703
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 {
Upvotes: 63
Views: 166538
Reputation: 103
Fixed by the below: I added the below and it fixed the problem for me - In this file: build.gradle.kts (module :app) add: implementation("androidx.exifinterface:exifinterface:1.3.6")
Upvotes: 0
Reputation: 7220
You should add a theme
to your all activities (You should add theme
for all application in your <application>
in your manifest)
but if you have set different theme to your activity you can use :
android:theme="@style/Theme.AppCompat"
or each kind of AppCompat
theme!
Upvotes: 13
Reputation: 150
I was getting this error while trying to setup react-native-bootsplash, in their documentation they say you have to change you application theme from this
<application
...
android:theme="@style/AppTheme">
to this
<application
...
android:theme="@style/BootTheme">
But what worked for me was to leave the application theme as android:theme="@style/AppTheme"
and change the activity theme, like that:
<activity
android:name=".SplashActivity"
android:theme="@style/BootTheme"/> <!-- HERE -->
Entire AndroidManifest.xml file
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rv_supplier"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- It's necessary because of react-native-qrcode-scanner -->
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/BootTheme"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/notification_ic"
tools:replace="android:resource" />
</application>
</manifest>
```
Upvotes: 1
Reputation: 1380
Note that there may be 2 styles.xml
in /values/
and /values-night/
, in your project, for when the OS setting is set to Light or Dark mode. In both you need to replace the default Theme with an AppCompat
Theme in case you have the Dark setting on. Sometimes is only ON at night, so your app may compile during the day but stop working after certain hour, causing a lot of debugging confusion and headache. This also causes it to fail only in some devices (sim vs real for example):
old
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
new
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
Upvotes: 3
Reputation: 31
Faced same issue. If your application is using Theme.MaterialComponents...... then other place if using @android:style/Theme.... then this issue faced.
Upvotes: 0
Reputation: 41
This Error comes, when you use a AlertDialog in an activity. If you want get solution of this problem, you just need to make sure that in which activity you wanted to show the AlertDialog popup, this context must be like Demo.this. never use the getApplicationContext.
Upvotes: 2
Reputation: 1046
Used to face the same problem. The reason was in incorrect context passing to AlertDialog.Builder(here)
. use like
AlertDialog.Builder(Homeactivity.this)
Upvotes: 45
Reputation: 191728
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
Upvotes: 129
Reputation: 764
If you add the android:theme="@style/Theme.AppCompat.Light"
to <application>
in AndroidManifest.xml file, problem is solving.
Upvotes: 5