Alert Dialog在Android 13上未正确显示。

huangapple go评论73阅读模式
英文:

Alert Dialog not showing properly Android 13

问题

> 亲爱的开发者们!我在使用Java进行Android开发时遇到了一个问题,Alert Dialog在Android 13上没有正确显示。有其他人遇到过这个问题或者有任何解决方法吗?任何帮助将不胜感激!

private void showOptionalUpdateDialog() {
    if (!isFinishing()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Update Available")
                .setMessage("A new version of the app is available. Do you want to update?")
                .setPositiveButton("Update", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        redirectToAppStore();
                    }
                })
                .setNegativeButton("Not Now", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 处理“暂不更新”按钮点击
                        Log.e("NotNow", "点击");
                        Intent intent = new Intent(Splash.this, MainActivity.class);
                        startActivity(intent);
                        finish();
                    }
                })
                .setCancelable(false);

        AlertDialog dialog = builder.create();
        dialog.show();
    }
}

> 这是输出的截图:
Alert Dialog在Android 13上未正确显示。

英文:

> Hello dear developers! , I'm having an issue with an Alert Dialog not showing properly in Android 13 using Java for Android development. Has anyone else encountered this problem or have any insights on how to resolve it? Any help would be greatly appreciated!

    private void showOptionalUpdateDialog() {
        if (!isFinishing()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Update Available")
                    .setMessage("A new version of the app is available. Do you want to update?")
                    .setPositiveButton("Update", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            redirectToAppStore();
                        }
                    })
                    .setNegativeButton("Not Now", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Handle "Not Now" button click
                            Log.e("NotNow", "click");
                            Intent intent = new Intent(Splash.this, MainActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    })
                    .setCancelable(false);

            AlertDialog dialog = builder.create();
            dialog.show();

          
        }
    }

> This is the Output screenshot :
Alert Dialog在Android 13上未正确显示。

答案1

得分: 1

如果输出屏幕显示“Update Available”并且对话框的按钮和内容不太清晰可见,可能是由于Android 13中AlertDialog的默认样式发生了变化。
为确保按钮和内容正确显示,您可以尝试为AlertDialog应用自定义主题。通过应用自定义主题,您可以自定义AlertDialog的外观和样式,以确保它在Android 13中正确显示,并与您的应用的整体外观和感觉相匹配。

英文:

If the output screen is showing "Update Available" and the buttons and content of the dialog is not clearly visible, it might be due to changes in the default styling of AlertDialogs in Android 13.
To ensure that buttons and content is displayed properly you can try applying a custom theme to the AlertDialog. By applying a custom theme, you can customize the appearance and style of the AlertDialog to ensure that it displays correctly in Android 13 and matches the overall look and feel of your app.

huangapple
  • 本文由 发表于 2023年7月13日 17:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定