Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DialogFragment title not showing

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?

like image 895
TareK Khoury Avatar asked Sep 04 '15 19:09

TareK Khoury


2 Answers

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> 
like image 77
TareK Khoury Avatar answered Oct 12 '22 22:10

TareK Khoury


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); 
like image 37
Hpsaturn Avatar answered Oct 12 '22 22:10

Hpsaturn