如何居中android.support.v4.app.DialogFragment标题?

时间:2019-02-21 10:31:15

标签: android android-dialogfragment

我正在尝试在当前的Android应用程序中使用android.support.v4.app.DialogFragment

我希望通过设置文本大小(20sp),文本样式(BOLD)并将标题水平居中来设置DialogFragment标题的样式。

我可以成功设置文本大小和样式,但不能居中。

是否可以将dialogFragment的标题居中?

如果是,怎么办?

到目前为止,我的代码是:-

   <!-- Define your custom dialog theme here extending from base -->
    <style name="AppDialogTheme" parent="Theme.AppCompat.Light.Dialog">
        <!-- Define color properties as desired -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">#000</item>
        <item name="android:textColorHighlight">@color/background_url</item>
        <item name="colorAccent">@color/dark_grey</item>
        <item name="colorControlNormal">@color/colorPrimaryDark</item>
        <!-- Define window properties as desired -->
        <item name="android:windowNoTitle">false</item>
        <item name="android:windowTitleStyle">@style/CustomMenuTitle</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>

    <style name="CustomMenuTitle" parent="@style/DialogWindowTitle">
        <item name="android:textSize">30sp</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="DialogWindowTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
        <item name="android:maxLines">1</item>
        <item name="android:scrollHorizontally">true</item>
        <item name="android:textAppearance">@android:style/TextAppearance.DialogWindowTitle</item>
    </style>

我的DialogFragment

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.AppDialogTheme);
}

我在哪里弄错了?

0 个答案:

没有答案