对话框片段中未显示标题
Title not Displayed in Dialog Fragment
我有以下样式应该显示对话框的标题
<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
但是,对话框不显示 title.The 对话框,如下图 。我还包含了用于初始化视图的代码
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();
}
在您的 AppTheme 上添加 <item name="android:dialogTheme">@style/CustomDialog</item>
喜欢
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:dialogTheme">@style/CustomDialog</item>
</style>
我有以下样式应该显示对话框的标题
<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
但是,对话框不显示 title.The 对话框,如下图
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();
}
在您的 AppTheme 上添加 <item name="android:dialogTheme">@style/CustomDialog</item>
喜欢
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:dialogTheme">@style/CustomDialog</item>
</style>