这里是初学者。
我无法创建警报对话框。当我使用`alertDialog.show();
时会发生此错误-
java.lang.IllegalStateException:您需要使用Theme.AppCompat 活动的主题(或后代)。
我的代码
logoImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder=new AlertDialog.Builder(getApplicationContext());
builder.setTitle("hello");
builder.setMessage("hello how are you");
AlertDialog alertDialog= builder.create();
alertDialog.show(); //line
}
});
我的日志猫。
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:94)
at android.support.v7.app.AlertController.installContent(AlertController.java:232)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:279)
at android.app.Dialog.dispatchOnCreate(Dialog.java:394)
at android.app.Dialog.show(Dialog.java:283)
at com.abmm.include_activity$15.onClick(include_activity.java:459)
谢谢你..
答案 0 :(得分:0)
更改
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
到
AlertDialog.Builder builder = new AlertDialog.Builder(this);