Android中SlidingDrawer开发报错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 提供的主题,前者的话.. 阅读详情

Android抽屉开发报错You need to use a Theme.AppCompat theme (or descendant) with this activity.
方法1:
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:public class MainActivity extends ActionBarActivity 改成activity继承自Activity:
方法2:
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:
android:theme=”@style/Theme.AppCompat.Light.NoActionBar”
完整代码如下:

<activity android:name=".module.view.activity.KuwoMusicPlayActivity"
            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>

这个方法可以解决问题。
android(SlidingDrawer)实现代码
布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_red_light"
    tools:context="com.json.zjs.a20180905.MainActivity">

    <SlidingDrawer
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:content="@+id/content"
        android:handle="@+id/layout1"
        android:orientation="horizontal">
        <!--设置引导按钮-->
        <LinearLayout
            android:id="@+id/layout1"
            android:layout_width="35dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher" />
        </LinearLayout>
        <!--设置抽屉内容-->
        <TextView
            android:id="@+id/content"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:background="#f0f0"
            android:text="asdcfasghda" />

    </SlidingDrawer>
</RelativeLayout>
activity文件

package com.json.zjs.a20180905;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

}
style 文件:

<resources>

    <!-- Base application theme. 设置去除actionbar之后全屏显示,标题栏去掉 -->
    <style name="AppTheme" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>
清单文件:
<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="@style/Theme.AppCompat.Light.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

如何实现去掉标题栏:
第一种:
style 中设置

<style name="AppTheme" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen">

activity直接集成Activity,清单文件中的activity的theme不做处理!
第二中:、
继承AppCompatActivity,但是需要在清单文件中指定theme
theme需要在style中手动设置

<style name="AppTheme.NoTitle_FullScreen"> <!--自定义主题名称-->
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

效果:这里写图片描述
打开抽屉
这里写图片描述
支持点击和拖拽
这里写图片描述

基于深度学习的涂胶缺陷类型检测:数据集处理与YOLOv8模型实现 本文提出了一种基于YOLOv8深度学习的涂胶缺陷检测系统,针对断胶、溢胶、缺胶、气泡及胶条宽度异常等常见缺陷类型,实现了从数据采集到模型部署的完整解决方案。系统采用工业相机采集涂胶图像,通过多形态数据增强策略解决样本稀缺问题,利用YOLOv8框架实现高效检测。相比传统人工目检和规则式机器视觉方法,该系统在检测精度(mAP达97.5%)和实时性(单图检测耗时0.038秒)方面表现优异,可满足智能制造场景下的涂胶质量检测需求。 阅读详情

相关推荐

普通人如何上岸华为OD-面试总结

总共有3道算法题,100分值的两道,200分值的一道,不同的毕业院校和专业,通过机试的分值不一样,最少需要150分通过,提前和hr联系,了解自己需要多少分通过。重中之重:哪怕你是背的题库,也请你一定不要直接抄原来的,最好是变更下方法名,否则会判定你重复率过高,从而失去后面的面试机会(实在是不会做再用此方法,凑分数所用,面试官能看到你的代码,会影响你的面试评价)本人女,所以还问道了婚育计划,有对象这点可以说,没有问题,但是如果可以的话,生孩子的时间,可以给hr说这几年不考虑。如果说没有难题,直接就挂了。

weixin_47767264的博客 5460

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.

little_monkey_92的博客 2万+

fins协议握手信号服务器响应,欧姆龙FinsTCP与FinsUDP协议解析 —— 利用Wireshark对报文逐字节进行解析详细解析附含报文模拟器等...

前言 – Fins欧姆龙这个协议网上极少有相关的模拟器、Tcp的这一块倒是有但是Udp的基本都是不可用1、 Fins协议结构也很简单 协议分为两种 一种tcp一种udp2、 Tcp比Udp的报文会多一层tcp的head头部3、 Udp回应报文在Wireshark中是解析不到(因为他按照UDP的格式去解那指定是解不到)好长时间没有更新过博客了、也比较懒= = 。一、Read(TCP)发包那么这个就很...

weixin_32491317的博客 4442

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

建议收藏:华为海思IC设计笔试题,含解析(附下载)

接触过的部门有麒麟芯片、CPU/GPU,总体面试感觉非常好,规范且认真,第一轮手撕代码状态机+复盘机考题+瞄准几个知识点深挖,时间1hour+;一二轮面试是连着的,所以很累。但是岗位就那么多,在面试的时候,很多同学因为准备不充分,与岗位失之交臂,无缘进入该公司。时序电路有记忆功能,不会产生锁存器,锁存器一般在组合逻辑中case写不全,else写不全,或者敏感列表写不全。

nuoweishizi的博客 3289

【PDN仿真笔记9-使用Sigrity PowerDC进行IR Drop仿真的方法】

使用Sigrity PowerDC进行IR Drop进行仿真的方法

qq_42682826的博客 8008

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

说明你的 Activity 正在使用需要支持库主题(如。)的组件,但你没有为它指定基于。

xueyoubangbang的博客 2678

别再对着数据手册画图了!用HFSS 2023 R2快速复现ESP-01的PCB天线(附模型文件)

本文详细介绍了使用HFSS 2023 R2逆向复现ESP-01 PCB天线的五个关键步骤,包括逆向工程准备、高效建模技巧、材料与边界设置、激励与求解配置以及结果分析与设计验证。通过参数化建模和智能边界检测,大幅提升仿真效率,适用于WIFI和蓝牙设备的射频设计优化。

weixin_30832143的博客 77

解决 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. 两种解决办法: 1、在创建的activity时,如果不需要继承AppCompatActivity的话,就直接继承Activity。 2、如果必须要继承AppCompatActivity的话,我们看另一种办法: 将AndroidManifest.xml文件中关于Activ

DerMing_You的博客 7036

ArcGIS实战:地形湿度指数(TWI)计算全流程解析

本文详细解析了ArcGIS中地形湿度指数(TWI)的计算全流程,从DEM数据获取、填洼处理到水流方向与汇流累积量计算,最终实现TWI的精准计算。通过实战步骤指导,帮助读者掌握水文建模和土壤湿度预测的关键技术,适用于农业规划、生态研究等领域。

weixin_29231725的博客 872

【深度学习新浪潮】为什么OpenClaw这么吃token?

OpenClaw 高 Token 消耗的核心是 Agent 多轮思考、工具调用上下文累积,以及平台内置的模板/多模型协同开销;PD 分离在 OpenClaw 中可针对性解决长上下文 Prefill 阻塞、KV Cache 复用低效问题,是提升其推理效率的核心优化手段,主要落地在长上下文处理与生成阶段解耦、KV Cache 集中管理、动态资源调度三个方向。

专注:太空算力、AI infra、异构调度、大模型成本工程 421

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

大脸猫的博客 9822

迟滞电压比较器电路的原理与计算

迟滞电压比较器是一种具有双阈值特性的电路,通过正反馈机制实现抗噪声干扰功能。文章详细分析了其工作原理,包括同相型和反相型两种结构的电压阈值计算与电阻设计方法,并提供了已知门限求电阻和已知电阻求门限的推导公式。工程应用中需注意输出类型匹配、电阻取值范围、噪声裕量设计等问题。该比较器在信号处理、波形转换等场景中具有重要应用价值,设计时需综合考虑供电电压、参考电压和噪声特性等因素。

硬核科技 2688

解决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万+

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Android错误之: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. 原因分析:Activity继承的不是Activity而是兼容包,所以一定要使用兼容包AppCompat的主题。 解决方法:根据Ap

Yyongchao的博客 2037

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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

一:错误场景 自定义一个Activity的theme;而这个Activity继承自v7包中的AppCompatActivity或者ActionBarActivity:在Activity中指定相应的theme:android:theme="@style/Transparent"配置相应的styles.xml:<style name="Transparent" parent="AppTheme.Bas

喜欢你就像站在灿烂的晴空下,玻璃心碎一地,每片渣却都在发光。 1527

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

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

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

hkz0704的博客 2122

Android 项目报错java.lang.IllegalStateException: You need to use a Theme.AppCompat theme

错误日志:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 1.报这个错的原因是Activity继承了兼容包的类,比如AppCompatActivity,直接将AppCompat改为Activity即可 ...

qq_33157101的博客 1426

《第一行代码》61页错误:You need to use a Theme.AppCompat theme (or descendant) with this

抱着《第一行代码》第2版,码到61页,发现一个坑。在调用DialogActivity的时候,不管是真机调试还是AndroidStudio模拟器都会出错闪退。Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.意思是...

子夜小雨落满围城 964

Android异常-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. 异常分析: 异常的意思是:你需要使用一个theme.appcompat主题(或后代)与此活动。 为什么会有这种情况出现,是因为activi

浅浅同学的开发笔记 2万+

我的Android进阶之旅------>解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity....

#1、错误描述 今天,想实现Activity不显示标题栏的效果,在项目的AndroidManifest.xml文件,对相应的Activity添加属性 android:theme="@android:style/Theme.NoTitleBar" 具体代码如下: <activity android:nam...

weixin_34080951的博客 1402

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

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

不服输的小乌龟 1167
上一篇: Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.service.HiveServerException
下一篇: Android build.gradle(app)介绍
JSON_ZJS
博客等级 码龄9年 30粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值