android setPositiveButton и setNegativeButton делают сломанную кнопку на уровне SDK 26 - PullRequest
0 голосов
/ 26 января 2019

Это мой код

case DIA_SURRENDER:
    return new AlertDialog.Builder(this)
        .setIcon(R.drawable.booksmall)
        .setTitle(R.string.END_OF_DUEL)
        .setMessage(R.string.END_OF_DUEL2)
        .setPositiveButton(R.string.BUTTON_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Toast.makeText(Duel_CalculatorActivity.this, R.string.INITIALIZE, Toast.LENGTH_SHORT).show();
                    Initialize();
                }
        })
        .setNegativeButton(R.string.BUTTON_cancel, null)
        .create();

Это диалоговое окно в старой версии. И я хочу такой же в новой версии.

Но в sdk26 диалоговое окно показывается как

Старая версия и новая версия используют один и тот же код для этого диалога. Как восстановить диалог старой версии?

Спасибо за вашу помощь.

1 Ответ

0 голосов
/ 26 января 2019

Попробуйте это

  new AlertDialog.Builder(this, R.style.MyAlertDialogTheme)
            .setIcon(R.drawable.booksmall)
            .setTitle(R.string.END_OF_DUEL)
            .setMessage(R.string.END_OF_DUEL2)
            .setNegativeButton(android.R.string.no, null)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MainActivity.super.onBackPressed();
                    quit();
                }
            }).create().show();

Style

  <style name="MyAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorTag</item>
    <item name="android:colorBackground">@color/colorPrimary</item>
</style>
...