You need to use a Theme.AppCompat theme (or descendant) with this activity.

细说 AppCompat 主题引发的坑:You need to use a Theme.AppCompat theme with this activity! 一般来说按照文档的建议去做,出现问题的概率很低。但很多人的情况不同,每每会发生意外状况,就比如这次没有使用 AppCompat 主题引发的坑! AppCompat 框架作为 Jetpack 集合的基石,非常重要。Android Studio 上创建的默认项目都会自动集成 AppCompat 框架,并采用其提供的 AppCompatActivity 作为 Activity Base。 App 侧给 Activity 配置的主题一般扩展自 SDK 提供的系统主题或 AppCompat 提供的主题,前者的话.. 阅读详情
错误描述为:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

起因:
我想在Manifest中设置我的activity全屏,代码如下:
  1. <activity  
  2.     android:name=".MainActivity"  
  3.     android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  
  4.     android:label="@string/app_name" >  

原因:
从错误提示中提到Theme.AppCompat theme,这是因为我们的activity一定是继承了兼容包中的类,
比如我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。
所以就要使用与其配合的AppCompat的theme才行。

解决:
1.根据提示来使用AppCompat的theme,如下:
  1. <activity  
  2.     android:name=".MainActivity"  
  3.     android:theme="@style/Theme.AppCompat.Light.NoActionBar"  
  4.     android:label="@string/app_name" >  
不过我要设置全屏,但我并没有找到,所以虽然错误不见了,但并没有达到我的预期。

2.如果不是那么强烈需要继承自ActionBarActivity,就直接继承Activity吧。问题自然搞定!
PHP 对接建行生活订单推送接口 php对接建行订单推送 阅读详情

相关推荐

Photoshop免费获取指南:官方试用与开源替代方案详解

图像处理软件是数字内容创作的核心工具,其工作原理基于像素编辑、图层叠加与算法滤镜。这类软件的技术价值在于为设计师、摄影师和内容创作者提供了强大的视觉表达能力,广泛应用于平面设计、UI/UX、摄影后期及社交媒体内容制作等场景。在众多工具中,Adobe Photoshop以其全面的功能和行业标准地位备受关注。对于希望免费体验或使用的用户,存在合法且安全的途径。其中,Adobe官方提供的7天免费试用版允许用户在安全环境下体验完整功能,而开源替代方案如GIMP则提供了长期免费的强大图像编辑能力。理解这些合法获取方式

cigang4063的博客 524

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

异常信息 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 异常分析 异常的意思是:你需要使用一个 theme.appcompat 主题(或后代)与此活动。为什么会有这种情况出现,是因为 Activity 继承的是 AppCo...

大脸猫的博客 9821

MIMO技术入门

MIMO:多天线技术,发射端和接收端有多个天线(注意:并不是指多个天线板,而是多套振子,每一套是一个独立的天线。) 4G:2、8天线 5G:4、64天线(64T64R) 手机也是多天线 MIMO实现效果的分类: 1)空间分集 。2)空间复用。3)波束赋形。 空间分集(space diversity) 作用:提升接收质量 利用多个天线发射或者接收一个数据流,避免单个信道衰落对整个链路的影响。(比如你的耳机坏了一只并不影响另一只) 空间复用(space multiplexing) 作用:提升速率 利

About1129的博客 2876

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

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

xie__jin__cheng的博客 2570

SAE J1939协议详解

SAE J1939协议是由美国汽车工程师协会(SAE)制定的主要针对商用车的CAN总线通讯协议,其基础是CAN2.0B协议,面向对象为客车和载重货车;船舶、农业机械等非路面设备。1.SAE J1939协议文档结构如下图:2.CAN的发展概况20世纪80年代,Bosch的工程人员开始研究用于汽车的串行总线系统,1986年, Bosch在SAE(汽车工程师协会)大会上提出了 CAN,1987年,INTEL就推出了第一片CAN控制芯片—82526;随后Philips半导体推出了82C200。

weixin_46184756的博客 8445

Unity URP管线下的Highlight Plus插件,从导入到实现物体高亮的保姆级避坑指南

本文详细解析了在Unity URP管线中使用Highlight Plus插件实现物体高亮的完整流程与常见问题解决方案。从URP环境配置、插件导入避坑到相机设置优化,提供了一套完整的保姆级指南,帮助开发者高效解决高亮效果不显示等典型问题,并包含移动端性能优化与复杂场景管理的高级技巧。

weixin_27379781的博客 408

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

在安卓开发过程中,MainActivity在继承Activity或者AppCompatActivity类时,是整个开发过程中一个很重要的工具方法。其中AppCompatActivity的功能要比Activity功能多。但是在使用AppCompatActivity是,会出现。此时需要在代码中增加。

hkz0704的博客 2122

STM32F407VET6与CH395Q串口通信实战:从零搭建以太网客户端(附完整代码)

本文详细介绍了基于STM32F407VET6微控制器与南京沁恒微CH395Q以太网芯片,通过串口通信从零搭建TCP客户端应用的完整实战过程。内容涵盖硬件连接、驱动层设计、基于FreeRTOS的任务实现以及核心调试技巧,并提供了完整的代码示例,帮助嵌入式开发者快速实现设备联网功能。

weixin_29179311的博客 415

You need to use a Theme.AppCompat theme (or descendant) with this activity. 完美解决

先看一条错误信息:Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. android Studio在执行新建项目时出现此错误,出现此错误的原因就是: Activty继承自android.support.v7...

lizhong 7万+

物联网组网技术优缺点对比:蓝牙、LoRa、wifi、NB-IoT、ZigBee等

1.前言 最近对物联网产品自组网技术选型,找到合适的组网技术,让产品自行组网并完成数据的传输。 2.参数对比

谁念西风独自凉 4万+

泛微系统流程表单获取节点操作者

泛微系统流程表单获取节点操作者 select typename 流程类型, workflowname 流程名称, nodename 节点名称, (case when nodetype=0 then '创建' when nodetype=1 then '审批' when nodetype=2 then '提交' when nodetype=3 then '归档' else '' end) as 节点类型, groupname 节点操作组, (case when type=1 then '部门+安

烧硬盘 4615

【Android初级】You need to use a Theme.AppCompat theme (or descendant) with this activity解决办法

这是我第一次根据Android官网指导写的APP,链接如下: Start Another Activity 每一步都严格参照了官网指导,一步一步敲代码、运行,结果报了如下错误: 10-08 18:08:40.878 18503 18503 E AndroidRuntime: Caused by: java.lang.IllegalStateException: You need to us...

snowyeti的博客 2382

如何用libwebsocket库在stm32F407上实现websocket客户端?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1134

报错:You need to use a Theme.AppCompat theme (or descendant) with this activity.

报错:You need to use a Theme.AppCompat theme (or descendant) with this activity. 学习 Activity 生命周期时希望通过 Dialog 主题测试 onPause() 和 onStop() 的区别,点击按钮跳转 Activity 时报错: 复制代码 E/AndroidRuntime: FATAL EXCEPTION: m...

mleage的博客 679

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

解决You need to use a Theme.AppCompat theme (or descendant) with this activity.

解决 You need to use a Theme.AppCompat theme (or descendant) with this activity. 解决方法 方法1: 创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。 如将activity继承自AppCompatActivity: public class MainAct...

lady_zhou的博客 3万+

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

解决You need to use a Theme.AppCompat theme (or descendant) with this activity

错误信息 2019-07-24 15:35:40.385 18490-18490/com.adojayfan.rntest E/AndroidRuntime: FATAL EXCEPTION: main Process: com.adojayfan.rntest, PID: 18490 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activ

adojayfan的博客 1万+

[debug]You need to use a Theme.AppCompat theme (or descendant) with this activity.

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 问题描述及原因 为Activity添加透明主题android:theme="@android:style/Theme.Translucent", 报错java.lang.Illega...

mtyn2015的博客 168

You need to use a Theme.AppCompat theme (or descendant) with this activity

报错:You need to use a Theme.AppCompat theme (or descendant) with this activity.按照解释说明修改theme 初步推断再写Log.v的时候报错应该和Log有关 <application android:allowBackup="true" android:icon="@mipmap/ic_faceid" android:label="@string/app_name" android:suppor

weixin_40212700的博客 277

使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决

以前由于继承自ActionBarActivity用得好好的,现在直接继承Activity,使用AlertDialog,则会报以下这个错误: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.   可以这样解决,在st

Nothing 5061

报错方案:You need to use a Theme.AppCompat theme (or descendant) with this activity.

当你的报错为:You need to use a Theme.AppCompat theme (or descendant) with this activity.的时候. 第一步检查你的activity,通常你的activity应该是因为集成了AppCompatActivity,而你的Theme写法不被认可. 比如,你是否是这么写的 android:theme="@android:styl

心于高处自凌云 587

android Bug:You need to use a Theme.AppCompat theme (or descendant) with this activity解决方案

这个问题,不是大问题,,,但是遇到,还是蛮困扰的,,毕竟以前新建AppCompAtctivity都没问题,现在新建的都报错,肯定得从自己工程找原因,,提示很明显: You need to use a Theme.AppCompat theme (or descendant) with this activity. 中文翻译过来意思就是你需要使用一个Theme.AppCompat主题(或继承...

Yrish的博客 552
上一篇: android 学习路线二
下一篇: Error when inflating android.support.design.widget.TextInputLayout
下沉的代码
博客等级 码龄12年 2粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值