在服务android中显示自定义警报对话框

问题描述 投票:0回答:1

我试图在服务中显示自定义的警报对话框,但它显示了异常

Java.Lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

我不知道如何解决此异常,请帮我,以下是我尝试过的方法。

View view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.recommendations,null);
                    AlertDialog alertDialog;
                    AlertDialog.Builder builder=new AlertDialog.Builder(CalculationService.this);
                    builder.setView(view);
                    if (Constants.avg>Constants.watt){
                        alertDialog=builder.create();
                        alertDialog.show();
                        Button deviceOFF=view.findViewById(R.id.deviceoff);
                        deviceOFF.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                DatabaseReference status=database.getReference("status");
                                status.setValue("0");
                            }
                        });
                    }
java android service android-alertdialog
1个回答
0
投票

出现此问题的原因是,您试图将对话框主题应用于的活动正在扩展ActionBarActivity,而这需要应用AppCompat主题。

© www.soinside.com 2019 - 2024. All rights reserved.