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. C++智能指针剖析(下)boost::shared_ptr&其他

    1. boost::shared_ptr 前面我已经讲解了两个比较简单的智能指针,它们都有各自的优缺点.由于 boost::scoped_ptr 独享所有权,当我们真真需要复制智能指针时,需求便满足不 ...

  2. SpringBoot的@Enable*注解的使用介绍

    @EnableAsync或@EnableConfigurationProperties背后的运行原理,是使用了@Import注解. @Import({User.class,Role.class,MyC ...

  3. Redis数据类型Set

    Redis的SET是无序的String集合,它里面的元素是不会重复的. SADD,SMEMBERS SADD命令会添加新元素到SET,可以看到一次性可以添加一个或多个元素.SMEMBERS可以获取se ...

  4. status 返回当前请求的http状态码

    status属性返回当前请求的http状态码,此属性仅当数据发送并接收完毕后才可获取.完整的HTTP状态码如下: 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分 101 ...

  5. HTTP/1.1 chunked 解码

    0.简介 1.定义 RFC定义 https://tools.ietf.org/html/rfc2616#section-3.6.1 Chunked-Body = *chunk last-chunk t ...

  6. python DNN

    exam_relu_softmax_dnn ''' 문) bmi.csv 데이터셋을 이용하여 다음과 같이 DNN모델을 생성하시오. 조건1> X,Y변수 -> X변수 : heigh ...

  7. (八)shell工具-重点

    8.1 cut cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的.cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段输出. 1.基本用法 cut [选项参数]  fil ...

  8. 自我介绍&软工实践博客点评

    想想既然写了点评博客,那就顺便向同学们介绍下自己吧. 我是16届计科实验班的,水了两件小黄衫,于是就来当助教了_(:_」∠)_ 实话说身为同届生来当助教,我心里还是有点虚的,而且我还是计科的..感觉软 ...

  9. 用ttBulkCp把excel中的数据导入到timesten数据库中

    最近要做数据预处理,需要用到数据库.而且是以前从来没听说过的TimesTen. 首要目标是要把Excel里的数据,导入到TimesTen数据库中.而TimesTen在win10里用不了,于是我就在虚拟 ...

  10. Autograd:自动微分

    Autograd 1.深度学习的算法本质上是通过反向传播求导数,Pytorch的Autograd模块实现了此功能:在Tensor上的所有操作,Autograd都能为他们自动提供微分,避免手动计算导数的 ...