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

查看:248
本文介绍了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天全站免登陆