Android DialogFragment with AppCompat theme issue

I am trying to create a DialoFragment with an AppCompat theme, but when I use the AppCompat theme, the dialog title is not displayed.

I use a specific style:

<style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog"/> 

When the parent theme is changed to:

 <style name="DialogFragment" parent="android:Theme.Material.Light.Dialog"/> 

or

 <style name="DialogFragment" parent="android:Theme.Holo.Light.Dialog"/> 
Headline

displayed correctly.

Code of my dialogue:

 public class InfoDialog extends DialogFragment { public static final String TAG = InfoDialog.class.getName(); @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().setTitle(getString(R.string.dialog_title)); return dialog; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogFragment); } @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.info_dialog, container, false); } } 

Any ideas what causes the problem? Using the com.android.support:appcompat-v7:22.2.0 application, maybe this is a platform error?

+8
android android-dialogfragment appcompat
source share
3 answers

Try expanding AppCompatDialogFragment instead of DialogFragment. That should do the trick.

+10
source share

Theme.AppCompat.Light.Dialog does not set the default header window.

Try something like:

 <style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog"> <item name="android:windowNoTitle">false</item> </style> 
+2
source share

As far as I know, when you override onCreateView, you override the default layout of the dialog snippet. therefore, I suggest you create your own fragment of dialogue fragment.

here is a sample xml layout.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="@drawable/rounded_dialog" android:orientation="vertical" android:padding="@dimen/margin_standard"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="@dimen/margin_standard" > <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/dialog_error_prompt_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/lorem" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="@dimen/margin_standard" android:layout_marginLeft="@dimen/horizontal_margin" android:layout_marginRight="@dimen/margin_standard" android:layout_marginTop="@dimen/margin_standard" > <TextView android:id="@+id/dialog_error_prompt_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/lorem_long" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:orientation="horizontal" android:weightSum="1" android:padding="@dimen/margin_standard"> <TextView android:visibility="invisible" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="@dimen/margin_standard" android:clickable="true" android:padding="@dimen/margin_standard" android:text="@string/cancel" android:textAppearance="?android:attr/textAppearanceButton" android:layout_weight=".70" android:gravity="center" android:textColor="@color/primary"/> <TextView android:gravity="center" android:layout_weight=".30" android:id="@+id/dialog_error_prompt_positive_button" android:layout_width="wrap_content" android:layout_height="@dimen/standard_button_height" android:layout_margin="@dimen/margin_standard" android:background="@drawable/primary_button_selector_background" android:clickable="true" android:padding="@dimen/margin_standard" android:text="@string/ok"`enter code here` android:textAppearance="?android:attr/textAppearanceButton" android:textColor="@color/background_floating_material_light"/> </LinearLayout> </LinearLayout> 
0
source share

All Articles