Android中SlidingDrawer开发报错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.
方法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>
清单文件:
<applicationandroid: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>
效果:
打开抽屉
支持点击和拖拽
Android中SlidingDrawer开发报错You need to use a Theme.AppCompat theme (or descendant) with this activity.相关推荐
- 用友uap开发报错:流程平台缓存中不存在该单据或交易类型=xxx
用友uap开发报错:流程平台缓存中不存在该单据或交易类型=xxx 1.错误如图 2:如下图找到单据类型管理: 3.打开增加相关单据类型,完善信息. 4.如图找到单据 动作管理打开 5.在单据动作管理中 ...
- Go开发报错 -- Golang strings.Builder type undefined
Go开发报错 -- Golang strings.Builder type undefined 在Go开发中,Go语言版本 go 1.10 以下版本,使用strings.Builder报错 I was ...
- Android中SlidingDrawer介绍【安卓进化三十四】
Android中SlidingDrawer介绍[安卓进化三十四] 安卓中1.5后加入了SlidingDrawer[隐藏式抽屉],设计原理在你的UI布局有限的情况下,放不下太多的控件的时候,可以考虑用这 ...
- 【错误记录】Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )
文章目录 一.报错信息 二.解决方案 一.报错信息 运行 Android 应用时 , 报错 ; 报错信息如下 : 2021-08-04 21:04:12.067 26338-26338/com.exa ...
- 关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法 - 转
android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme ( ...
- Android之You need to use a Theme.AppCompat theme (or descendant) with this activity.
1 问题 点击activity的时候,崩溃日志如下 You need to use a Theme.AppCompat theme (or descendant) with this activity ...
- 【错误记录】Flutter 混合开发报错 ( Android 端与 Flutter 端 EventChannel 初始化顺序错误导致无法通信 | EventChannel 通信流程 )
文章目录 一. 报错信息 二. Android 端与 Flutter 端 EventChannel 注册与监听流程 三. 解决方案 一. 报错信息 在 Android 端初始化 EventChanne ...
- 【小坑】Android 实现对话框会报错 (You need to use a Theme.AppCompat theme (or descendant) with this activity)
效果演示 有的时候,我们想Activity以小窗口的形式展示. 其实只需要添加上这么一行就可以了. android:theme="@style/Theme.AppCompat.Light.D ...
- Android中实现“程序前后台切换效果”和“返回正在运行的程序,而不是一个新Activity”...
ANDROID 一.首先是返回正在运行的程序,而不是新的ACTIVITY. 多网上关于 通知栏的例子都是打开一个新的Activity,代码也很多. 根据那些代码如下 public void s ...
最新文章
- MySQL:Innodb DB_ROLL_PTR指针解析
- SpringMVC的请求-文件上传-客户端表单实现
- 编写了html怎么测试,如何将测试结果写入HTMLTestRunner生成的报告标题中
- python程序中的内存泄露(matplotlib内存泄漏)
- python3 yield_详解Python3中yield生成器的用法
- 弥补性能鸿沟,傲腾在企业应用中加速普及
- wajueji.php,独家解析:为什么说斗山DX55-9C是5吨小挖掘机中的新机皇
- 红帽子linux 9.0下载,红帽子 RedHat linux 9.0 简体中文正式版 下载地址
- java计算器取余_java计算器代码,只有加减乘除和取余运算的??
- 浅谈IPv4/IPv6转换技术
- 松柏先生: 做品牌自己挣钱不算什么, 能让1000名山区绣娘都挣钱才牛!
- python祝福,1024,用Python抽取你的专属祝福!
- 商标注册要的一些重要基本常识(附:注册流程)
- 《Intel汇编语言程序设计》环境搭建
- The following signatures were invalid: EXPKEYSIG F42ED6FBAB17C654 的解决方法
- 动态生成网站地图sitemap.xml
- 分享一个react 图片上传组件 支持OSS 七牛云
- 用户日活月活怎么统计 - Redis HyperLogLog 详解
- NX二次开发 UFUN创建倒角特征 UF_MODL_create_chamfer
- 如何利用小程序+插件快速开发app?
热门文章
- G. GCD Festival(莫比乌斯、欧拉函数)
- HDU 5730 Shell Necklace(生成函数 多项式求逆)
- 2019年第十届蓝桥杯 C / C ++省赛 B 组真题题解
- P3345 [ZJOI2015]幻想乡战略游戏
- P5357 【模板】AC自动机(二次加强版) fail树
- Codeforces Round #628 (Div. 2) E. Ehab‘s REAL Number Theory Problem 巧妙的质因子建图
- CF1478A - Nezzar and Colorful Ball(数学)
- L - Two Ants Gym - 102823L
- jzoj3910-Idiot的间谍网络【倍增,dfs】
- jzoj3889-序列问题【dp,高精度】