android setPositiveButton&setNegativeButton在sdk 26级使损坏的按钮

时间:2019-01-26 08:21:15

标签: android android-dialog

这是我的代码

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();

This is the dialog in old version. And I want the same one in new version.

But in sdk26, the dialog shown as this

此对话框的旧版本和新版本使用相同的代码。 如何恢复旧版本对话框?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

尝试一下

  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 name="MyAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorTag</item>
    <item name="android:colorBackground">@color/colorPrimary</item>
</style>
相关问题