I've trying to create DialoFragment with AppCompat theme, but when i use AppCompat theme, dialog title is not shown.
I'am using defined style:
<style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog"/>
When parent theme will be changed to:
<style name="DialogFragment" parent="android:Theme.Material.Light.Dialog"/>
or
<style name="DialogFragment" parent="android:Theme.Holo.Light.Dialog"/>
title is displaying properly.
Code of my dialog:
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 is causing the issue?
Application use com.android.support:appcompat-v7:22.2.0
, maybe this is platform bug?
AppCompatTextView is an AppCompat widget that can only be used with a Theme.
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
Try extending AppCompatDialogFragment instead of DialogFragment. That should do the trick.
Theme.AppCompat.Light.Dialog
sets no title window in default.
Try something like below:
<style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With