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 问题解决
问题代码
void initCommitDialog(String message) {
mCommitDialog = new AlertDialog.Builder(context).create();
mCommitDialog.setCanceledOnTouchOutside(false);
mCommitDialog.show();
mCommitDialog.getWindow().setLayout(getResources().getDimensionPixelSize(R.dimen.papers_commit_main_width), getResources().getDimensionPixelSize(R.dimen.papers_commit_main_height));
mCommitDialog.getWindow().setContentView(R.layout.dialog_zhenti_papers_commit);(问题日志指出这行代码有问题)
mCommitDialog.getWindow().setBackgroundDrawableResource(R.drawable.radius_20_white_bg);
TextView tv_message = (TextView) mCommitDialog.getWindow().findViewById(R.id.dialog_zhenti_papers_commit_message_tv);
tv_message.setText(message);
mCommitDialog.getWindow().findViewById(R.id.dialog_zhenti_papers_commit_cacel_iv).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCommitDialog.dismiss();
}
});
mCommitDialog.getWindow().findViewById(R.id.dialog_zhenti_papers_commit_submit_iv).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPresenter.setCommitWhatEver();
mPresenter.commit(null);
}
});
}
问题日志
09-02 15:58:26.854 11821 11821 E AndroidRuntime: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.y(AppCompatDelegateImplV9.java:359)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.x(AppCompatDelegateImplV9.java:328)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.b(AppCompatDelegateImplV9.java:289)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AlertController.a(AlertController.java:226)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:259)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.app.Dialog.show(Dialog.java:274)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at cn.dream.ebag.classService.ui.exercise.paperView.PapersFragment.d(PapersFragment.java:592)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at cn.dream.ebag.classService.ui.exercise.paperView.PapersFragment.h(PapersFragment.java:579)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at cn.dream.ebag.classService.ui.exercise.paperView.e.a(PapersPresenter.java:102)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at cn.dream.ebag.classService.ui.exercise.paperView.PapersFragment.commit(PapersFragment.java:571)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at cn.dream.ebag.classService.ui.exercise.paperView.PapersFragment_ViewBinding$2.doClick(PapersFragment_ViewBinding.java:57)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.view.View.performClick(View.java:4781)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.view.View$PerformClick.run(View.java:19874)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
09-02 15:58:26.854 11821 11821 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
从日志可以看到问题的解决方法是给当前的 activity 使用 Theme.AppCompat 主题。
解决方法
给当前的 Activity 使用 ThemeAppCompat 主题。
未修改之前的主题
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowEnableSplitTouch">false</item>
<item name="android:splitMotionEvents">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@style/ActivityAnimStyle</item>
</style>
修改之后的主题
<style name="ServiceAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@color/translate</item>
<item name="android:windowAnimationStyle">@style/ActivityAnimStyle</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
更换主题之后,问题得到解决。
查看资源
http://anforen.com/wp/2016/04/alertdialog-java-lang-illegalstateexception-you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity/
https://blog.csdn.net/jyw935478490/article/details/72868751
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: FA ...
- Android 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 ...
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...
- You need to use a Theme.AppCompat theme
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dji.sdk.sample/com.dji.sdk.sa ...
- java.lang.IllegalStateException: 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 t ...
- 关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法
android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme ( ...
- Android Studio:You need to use a Theme.AppCompat theme (or descendant) with this activity. AlertDialog
学习<第一行代码>的时候遇到的问题. Process: com.example.sevenun.littledemo, PID: 2085 java.lang.RuntimeExcepti ...
- 开发中遇到的问题(一)——java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
1.错误描述: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) wit ...
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme
配置: 中设置theme为 <application android:allowBackup="true" android:icon="@mipmap/ic_lau ...
- Android Studio: 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 ...
随机推荐
- 三丶JavaScript 的基础学习(一)
知识预览 BOM对象 DOM对象(DHTML) 8 实例练习 JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言 ...
- python的pandas库学习笔记
导入: import pandas as pd from pandas import Series,DataFrame 1.两个主要数据结构:Series和DataFrame (1)Series是一种 ...
- boostrap日期时间插件datetimepicker使用过程的一些问题总结
1.汉化问题 虽然有转门的汉化脚本,不过如果简单使用的话自己稍微改一下源码就行了: var dates = $.fn.datetimepicker.dates = { en: { days: ['Su ...
- VIM 编辑器
可视化模块 进入vi/vim编辑器,按CTRL+V进入可视化模式(VISUAL BLOCK) 2 移动光标上移或者下移,选中多行的开头,如下图所示 3 选择完毕后,按大写的的I键,此时下方会提示进入“ ...
- spring boot jpa 使用update 报错解决办法
在spring boot jpa 中自定义sql,执行update操作报错解决办法: 在@Query(...)上添加 @Modifying@Transactional注解
- oracle数据库学习
trunc(number[,decimals])--number 待做截取处理的数值:decimals 指明需保留小数点后面的位数 CREATE PUBLIC DATABASE LINK Co ...
- Jmeter实现dubbo接口压测案例
当前项目中重构了消息服务,需要对消息服务接口做性能压测,评估消息服务的性能情况 通过和开发对接,目前消息服务是通过dubbo接口对内提供服务,所以才有了这边文章的记录 最初的压测这个dubbo接口有三 ...
- Oracle:select into 查询没有记录的解决办法
在数据库编程中,select into 语句可以将数据库的某些值赋值给程序的变量,使用起来非常方便.但很多时候也会遇到查询出来没有记录的情况,这时程序会出错. 可以使用 exception when ...
- Dalvik和ART
--摘自<Android进阶解密> DVM和ART都是在Zygote进程中诞生的 *DVM和JVM的区别* 1.基于的架构不同 DVM是基于寄存器的,它没有基于栈的虚拟机在复制数据时而使用 ...
- 视频播放—— H5同层播放器接入规范
H5同层播放器接入规范 x5-video-player-type 启用H5同层播放器 通过video属性“x5-video-player-type”声明启用同层H5播放器 x5-video-playe ...