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. css @import 导入文件

    导入另一个css文件 例如 <style type="text/css"> @import url(css/main.css); //导入css目录下的main.css ...

  2. 处理soapUI特殊返回报文 【原】

    String message ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + & ...

  3. Excel藏的很深(1)

    Excel 的强大功能, 神奇! 1.快速定位数据  ctrl+g 定位条件; 或者菜单中: 查找与选择->定位条件 (1) 删除所有的错误值(ref这种) (2) 实现空格自动填充0: ctr ...

  4. Python3学习十四

    1.  JS基本概念 网景和sun联合开发javascript javascript 三个部分:ECMAScript 语法    DOM(document object model)    BOM(b ...

  5. 运行Scrapy程序时出现No module named win32api问题的解决思路和方法

    有小伙伴在群里边反映说在使用Scrapy的时候,发现创建项目一切顺利,但是在执行Scrapy爬虫程序的时候却出现下列报错:“No module named win32api”,如下图所示,但是不知道怎 ...

  6. OpenCV中的KNN

    一.K近邻 有两个类,红色.蓝色.我将红色点标记为0,蓝色点标记为1.还要创建25个训练数据,把它们分别标记为0或者1.Numpy中随机数产生器可以帮助我们完成这个任务 import cv2 impo ...

  7. [转] 如何设置双网卡同时连接内网外网_bpao_新浪博客

    已剪辑自: http://blog.sina.com.cn/s/blog_5d3e229c0100skwe.html 如何设置双网卡同时连接内网外网 . 通过无线网络连接外网,确保连接成功后开始第二步 ...

  8. Codeforces 1070J Streets and Avenues in Berhattan dp

    Streets and Avenues in Berhattan 我们首先能发现在最优情况下最多只有一种颜色会分别在行和列, 因为你把式子写出来是个二次函数, 在两端取极值. 然后我们就枚举哪个颜色会 ...

  9. 2018-2019-2 网络对抗技术 20165319 Exp3 免杀原理与实践

    免杀原理及基础问题回答 免杀原理: 免杀指的是一种能使病毒木马免于被杀毒软件查杀的技术.由于免杀技术的涉猎面非常广,其中包含反汇编.逆向工程.系统漏洞等黑客技术,所以难度很高,一般人不会或没能力接触这 ...

  10. MongoDB的ORM框架——Morphia

    1.引入pom <dependency> <groupId>org.mongodb.morphia</groupId> <artifactId>morp ...