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 问题解决的更多相关文章

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

    学习 Activity 生命周期时希望通过 Dialog 主题测试 onPause() 和 onStop() 的区别,点击按钮跳转 Activity 时报错: E/AndroidRuntime: FA ...

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

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

  4. You need to use a Theme.AppCompat theme

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dji.sdk.sample/com.dji.sdk.sa ...

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

  6. 关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法

    android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme ( ...

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

  8. 开发中遇到的问题(一)——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 ...

  9. java.lang.IllegalStateException: You need to use a Theme.AppCompat theme

    配置: 中设置theme为 <application android:allowBackup="true" android:icon="@mipmap/ic_lau ...

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

随机推荐

  1. js中字符串的replace方法区分单双引号

    今天遇到一问题,js文件中调用字符串的replace方法,不起作用. 后来排查可能觉得replace("<option  value='1'>admin</option&g ...

  2. Day06(类包、内部类)

    在static静态方法中能直接调用的方法只能是静态方法.要想调用其它非静态方法,需要借助对象. 类包:是Java提供的一种管理类文件的机制.可以解决类名冲突问题,在开发庞大应用程序时帮助开发人员管理庞 ...

  3. javascript中所有函数参数都是按值传递

    在看<JavaScript高级程序设计>(第三版)的时候,传递参数这一节,里面提到 ECMAScript中所有函数的参数都是按值传递的 它自己的解释是, 把函数外部的值复制给函数内部的参数 ...

  4. 《ServerSuperIO Designer IDE使用教程》-1.标准Modbus和非标准协议的使用、测试以及驱动开发。附:v4.2发布

    ServerSuperIO Designer IDE v4.2版本更新内容: 增加ServerSuperIO.Host运行程序,可以使用IDE进行测试,Host为运行环境. 针对设备驱动增加导入监测点 ...

  5. python第十六天

    一.包 1.什么是包? 一系列模块的集合 2.有什么用? 包通过文件夹来管理一系列功能相近的模块 3.包重点? 包中一定有一个专门用来管理包中所有模块的文件   __init__ 4.什么是包名? 包 ...

  6. java TripleDES加密

    package com.zhx.base.util; import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher ...

  7. 2019 蓝桥杯省赛 A 组模拟赛(一)-忽明忽暗

    走廊里有 nn 盏灯,编号依次为 1,2,3,...,n,由学校电路控制中心管理.初始时,所有灯都是关闭的.某黑客入侵了学校电路控制中心,黑客想让灯忽明忽暗,进行了 n 轮操作.第 i 轮操作,会让所 ...

  8. 启动两个tomcat服务,以及使用nginx代理实现访问

    1.shoudowm.bat\startup.bat\catalina.bat, 将CATALINA_HOME修改为CATALINA_HOME_2 2.server.xml <Server po ...

  9. Dancing Links 学习笔记

    Dancing Links 本周的AI引论作业布置了一道数独 加了奇怪剪枝仍然TLE的Candy?不得不去学了dlx dlxnb! Exact cover 设全集X,X的若干子集的集合为S.精确覆盖是 ...

  10. linux shell 发送qq邮件失败

    安装 发送邮件功能 yum -y install postfix yum -y install mailx 使用 mail -s “fsfds” @qq.com < hh 第二次返回此信息 您在 ...