Android DialogFragment 标题未显示 [英] Android DialogFragment title not showing

查看:28
本文介绍了Android DialogFragment 标题未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建自定义 DialogFragment 时,我使用以下内容设置标题:

When creating a custom DialogFragment, i set the title using the following:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_dialog_add, container, false);      

    // Setting title here
    getDialog().setTitle("Add New");

    return v;
}

以上代码在 23 之前的 API 级别上对我来说工作正常.对于 API 23,标题根本不显示.

The above code works fine for me on API level older than 23. For API 23 the title is not showing at all.

知道为什么吗?以及如何在 API 23 上显示标题?

Any idea why? and how to make the title show on API 23?

推荐答案

通过在styles.xml中添加以下内容解决:

Solved by adding the following to the styles.xml:

<item name="android:dialogTheme">@style/CustomDialog</item>

<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">false</item>
</style>

这篇关于Android DialogFragment 标题未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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