Вам нужно использовать тему Theme.AppCompat (или потомок) с этим действием. В адаптере данных - PullRequest
0 голосов
/ 27 октября 2019

Я пытаюсь использовать 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();

1 Ответ

0 голосов
/ 28 октября 2019

Вы должны передать идентификатор темы вместе с Context, как это. если это вам помогло, то примите в качестве ответа.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.Theme_AppCompat_DayNight_Dialog_MinWidth);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...