Я пытаюсь использовать AlertDialog в RecyclerView, но у меня возникает следующая проблема: Вам нужно использовать тему Theme.AppCompat (или потомок) с этим действием. Работает тот же AlertDialog в классе Activityотлично, но не в DataAdapter.
стили
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
манифест
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simple">
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Адаптер данных
private Context mCtx;
holder.moreOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(mCtx,holder.moreOptions);
popupMenu.inflate(R.menu.card_popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.delete_note:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mCtx);
alertDialog.setTitle("Notice");
alertDialog.setMessage("Launching this missile will destroy the entire universe. Is this what you intended to do?");
// add the buttons
alertDialog.setPositiveButton("Launch missile", null);
alertDialog.setNeutralButton("Remind me later", null);
alertDialog.setNegativeButton("Cancel", null);
// create and show the alert dialog
AlertDialog dialog = alertDialog.create();
dialog.show();