关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法

本文介绍了在Android应用中遇到的关于AppCompat主题的问题及两种解决方案。一是更改Activity的继承方式,二是设置正确的主题样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android的一个小问题:

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

法一:

当在AndroidManifest.xml文件的application的节点设置了属性:

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

而Activity继承了ActionBarActivity就回出现上述错误,解决的办法就是让Activity去继承Activity而不是ActionBarActivity

改完之后删掉报错的部分,然后别忘了导入Activity包

法二:

在AndroidMenifest.xml中加入一句:

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

例子:

  <activity
        android:name="com.vmoksha.BaseActivity"
        android:label="@string/app_name" 
        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>

然后在styles.xml中加入主题资源:

  <style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light"> 
        <item name="android:windowNoTitle">true</item>
     </style>

即可

项目创建后有如下错误: AndroidManifest.xml文件的错误: 无法解析符号 '@style/Theme.FloatingSearchApp' READ_EXTERNAL_STORAGE is deprecated (and is not granted) when targeting Android 13+. If you need to query or interact with MediaStore or media files on the shared storage, you should instead use one or more new storage permissions: `READ_MEDIA_IMAGES`, `READ_MEDIA_VIDEO` or `READ_MEDIA_AUDIO`. Redundant label can be removed DatabaseHelper.kt文件的错误: 应为 <database name> 或 <defined table name>,得到 '$' Value must be ≥ 0 but `getColumnIndex` can be -1 Parameter 'question' is never used FloatingWindowService.kt文件的错误: Avoid passing `null` as the view root (needed to resolve layout parameters on the inflated layout's root element) 'TYPE_PHONE: Int' is deprecated. Deprecated in Java `onTouch` should call `View#performClick` when a click is detected Do not concatenate text displayed with `setText`. Use resource string with placeholders. String literal in `setText` can not be translated. Use Android resources instead. Variable 'answer' is never used Do not concatenate text displayed with `setText`. Use resource string with placeholders. String literal in `setText` can not be translated. Use Android resources instead. MainActivity.kt文件的错误: Unresolved reference: activity_main This declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details TextRecognizer.kt文件的错误: No value passed for parameter 'options' 'getter for defaultDisplay: Display!' is deprecated. Deprecated in Java 'getMetrics(DisplayMetrics!): Unit' is deprecated. Deprecated in Java Parameter 'context' is never used floating_window.xml文件的错误: Hardcoded string "问题将显示在这里", should use `@string` resource Hardcoded string "答案将显示在这里", should use `@string` resource
最新发布
06-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值