George
George

Reputation: 2997

Title not Displayed in Dialog Fragment

I have the following style that is supposed to display the Title of the Dialog box

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

However, the dialog does not display the title.The dialog looks like the image below Dialog With no title. I have also include the code that I use to initialize the view

void initView(int maxLength)
{
    setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);

    getDialog().setTitle(title);
    Window wnd = getDialog().getWindow();
    if (wnd != null)
        wnd.getAttributes().windowAnimations = R.style.dialog_animation;

    Button dismiss = root.findViewById(R.id.numeric_done);
    dismiss.setOnClickListener((View v) -> done());

    this.maxLength = maxLength;
    numericInputManager = new NumericInputManager(maxLength);

    intStack = new Stack<>();
    valueEnteredTV = root.findViewById(R.id.value_entered);

    initButtons();
    initRestrictions();
}

Upvotes: 1

Views: 349

Answers (1)

Tshego
Tshego

Reputation: 136

Add <item name="android:dialogTheme">@style/CustomDialog</item> on your AppTheme like

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:dialogTheme">@style/CustomDialog</item>
</style>

Upvotes: 1

Related Questions