You need to use a Theme.AppCompat theme (or descendant) with this activity(2018-08)
发布日期:2021-06-29 01:40:59 浏览次数:2 分类:技术文章

本文共 1238 字,大约阅读时间需要 4 分钟。

 

错误原因:

设置全部 Activity 全屏时,进行了如下配置:

<application

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    >

 

错误信息: 

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

android Studio 在执行新建项目时出现此错误,出现此错误的原因就是:

Activty 继承自 androidx.appcompat.app.AppCompatActivity,而不是 android.app.Activty。

 

两种完美的解决办法:

1、相关Activity直接继承Activity,不继承AppCompatActivity

import android.app.Activity;

//public class MainActivity extends AppCompatActivity {
public class MainActivity extends Activity {

 

2、如果必须要继承AppCompatActivity的话,我们看另一种办法

   根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置都要改成:

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

例如:

<activity

    android:name=".RegisterActivity"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<activity
    android:name=".MainActivity"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

 

参考博文:

 

 

 

 

 

 

 

 

转载地址:https://blog.csdn.net/YuDBL/article/details/108059311 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:移动端APP设计学习笔记整理:2、写布局与切图常见注意点
下一篇:Axure使用笔记:2、如何使用Axure制作软件原型

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月25日 21时15分16秒