如何解决:“您需要在此活动中使用Theme.AppCompat主题(或后代)” [英] How to fix: "You need to use a Theme.AppCompat theme (or descendant) with this activity"

查看:2057
本文介绍了如何解决:“您需要在此活动中使用Theme.AppCompat主题(或后代)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照视频说明,我无法在全屏模式下运行Android应用。尝试运行时,应用程序崩溃并显示错误。

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.

您需要与此同时使用Theme.AppCompat主题(或后代)活动

清单文件

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

样式文件

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

部分MainActivity可能有用

Partial MainActivity that may be useful

public class MainActivity extends AppCompatActivity {


推荐答案

您的应用程序具有AppCompat主题

Your application has an AppCompat theme

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

但是,您用不是主题的后代覆盖了Activity(它扩展了AppCompatActivity)。 AppCompat主题

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

您可以这样定义自己的全屏主题(注意 AppCompat parent = 中的

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

注意:可能有一个已经全屏显示的AppCompat主题,但是马上不知道

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

这篇关于如何解决:“您需要在此活动中使用Theme.AppCompat主题(或后代)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆