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 ...
随机推荐
- OPPO A3在哪里打开usb调试模式的详细教程
当我们使用电脑通过数据线连接上安卓手机的时候,如果手机没有开启Usb开发者调试模式,电脑则无办法成功读到我们的手机,这时我们需要找方法将手机的Usb开发者调试模式打开,这里我们叙述OPPO A3如何开 ...
- jQuery配合html2canvas 使用时 报错 Uncaught (in promise) Provided element is not within a Document
报错代码: 这个函数运行时 function download(){ var element = $("#demo"); //jquery 获取元素 //这里将会报错 html2c ...
- vue使用过滤器利用moment实现日期的格式化
import moment from 'moment' 定义局部 filters:{ dateString:function(value,format){ console.log(value,for ...
- C#应用编程小例子-02-窗体最大化和最小化窗体大小
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- elasticsearch 学习
docker run -p : -d elasticsearch #直接拉取运行 #指定条件搜索curl --request GET \ --url 'http://localhost:9200/im ...
- thinkPHP5扩展workerman
-安装workerman 首先通过 composer 安装 composer require topthink/think-worker -vvv 如果报错: Installation failed, ...
- Flink on yarn的配置及执行
1. 写在前面 Flink被誉为第四代大数据计算引擎组件,即可以用作基于离线分布式计算,也可以应用于实时计算.Flink可以自己搭建集群模式已提供为庞大数据的计算.但在实际应用中.都是计算hdfs上的 ...
- HeadFirst学习笔记-2.观察者(Observer)模式
认识观察者模式 我们用报纸和杂志的订阅为例来介绍: 报社的业务就是出版报纸. 向某家报社订阅报纸,只要他们有新报纸出版,就会给你送来.只要你是他们的订户,你就会一直收到新报纸. 当你不想再看报纸的时候 ...
- 部分手机浏览器存在将ajax请求当成广告过滤的情况,及解决方案
我们发现h5页面在某些浏览器请求不到数据,经过排查,是浏览器的广告拦截模块搞的鬼. 通过删减参数,发现adtype和adnum参数去掉后,接口可以正常请求,开始以为是官方拦截关键词带有ad的参数,后来 ...
- [OC] 各型号iPhone的屏幕分辨率与开发使用的数值