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

后端 未结 4 1098
傲寒
傲寒 2020-11-28 09:36

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 t

相关标签:
4条回答
  • 2020-11-28 10:09

    If you add the android:theme="@style/Theme.AppCompat.Light" to <application> in AndroidManifest.xml file, problem is solving.

    0 讨论(0)
  • 2020-11-28 10:18

    Used to face the same problem. The reason was in incorrect context passing to AlertDialog.Builder(here). use like AlertDialog.Builder(Homeactivity.this)

    0 讨论(0)
  • 2020-11-28 10:25

    u should add a theme to ur all activities (u should add theme for all application in ur <application> in ur manifest) but if u have set different theme to ur activity u can use :

     android:theme="@style/Theme.AppCompat"
    

    or each kind of AppCompat theme!

    0 讨论(0)
  • 2020-11-28 10:31

    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

    0 讨论(0)
提交回复
热议问题