【问题标题】:Title not Displayed in Dialog Fragment对话框片段中未显示标题
【发布时间】:2019-03-05 05:02:18
【问题描述】:

我有以下应该显示对话框标题的样式

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

但是,对话框不显示标题。对话框类似于 下方的图像。我还包含了用于初始化视图的代码

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

【问题讨论】:

标签: java android android-styles


【解决方案1】:

在您的 AppTheme 上添加 &lt;item name="android:dialogTheme"&gt;@style/CustomDialog&lt;/item&gt; 喜欢

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多