Al intentar abrir un dialog en mi aplicacion me salta ese error.
"You need to use a Theme.AppCompat theme (or descendant) with this activity"
He buscado y parece ser un fallo entre el manifest.xml y styles.xml pero no consigo hacerlo funcionar.
Error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
at android.support.v7.app.AlertController.installContent(AlertController.java:231)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:278)
at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
at android.app.Dialog.show(Dialog.java:262)
at com.enzo.practicaplataforma.ConsultaActivity$2.onItemLongClick(ConsultaActivity.java:138)
at android.widget.AbsListView.performLongPress(AbsListView.java:2972)
at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2921)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Este es el manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_j23"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_j23_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".EdicionModulo"></activity>
<activity android:name=".Portada" />
<activity android:name=".ConsultaActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
Archivo styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Codigo del dialog que intento abrir:
lvListaModulos.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, final long id) {
AlertDialog.Builder alerta = new AlertDialog.Builder(getApplicationContext());
alerta.setMessage("¿Desea marcar este modulo como aprobado?").setCancelable(false)
.setPositiveButton("SI", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getApplicationContext(),ConsultaActivity.class);
gp.actualizarTabla("'Aprobado'", id);
startActivity(intent);
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog titulo = alerta.create();
titulo.setTitle("Editar" + nModulo);
titulo.show();
return true;
}
});
Gracias de antemano.