Android DialogFragment title not showing

坚强是说给别人听的谎言 提交于 2019-11-27 05:41:46

问题


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;
}

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

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


回答1:


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>



回答2:


In your styles:

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

If your dialog is a fragment:

MyFragment myFragment = new MyFragment();
myFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);


来源:https://stackoverflow.com/questions/32405042/android-dialogfragment-title-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!