Android 6.0 对话框文本不出现 [英] Android 6.0 Dialog text doesn't appear

本文介绍了Android 6.0 对话框文本不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将手机更新到了 Android 6.0,但出现了以下 2 个对话框问题:

I updated my phone to Android 6.0 and I have these 2 problems with dialogs:

1)显示了标题,但消息不是用于警报对话框(已解决):

1)The title is shown but the messages isn't for alert dialog(SOLVED):

        new AlertDialog.Builder(context).setTitle("Title").setMessage("Message");

2) 也未显示自定义对话框片段的标题(未解决):

2)Also custom dialog fragment's title is not shown(NOT SOLVED):

        getDialog().setTitle("Title");

棒棒糖和旧版本都没有这个问题,我的手机更新到棉花糖后才出现这个问题.

There was not such a problem in lollipop or in older versions, the problem appeared only after updating my phone to marshmallow.

如何解决问题?

推荐答案

为 Lollipop 和较新的 android 版本使用带有主题的构造函数:

Use constructor with theme for Lollipop and newer android versions:

深色主题

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(context);
    }

对于浅色主题

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(context);
    }

这篇关于Android 6.0 对话框文本不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆