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

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

问题描述

我将手机更新为Android 6.0,并且出现以下两个对话框问题:

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天全站免登陆