使用多个主题时未应用DialogFragment标题文本

时间:2018-02-17 17:04:44

标签: android themes

我尝试在我的DialogFragment上设置标题文字,但它没有按照我的预期运作。唯一有效的是,如果onCreate() dialogFragment明确地这样做:

setStyle(DialogFragment.STYLE_NORMAL, MyStyl...............);

并以那种风格设置了

    <item name="android:windowNoTitle">false</item>

但我有多个主题,用户可以在运行时更改为主题,所以我喜欢这样设置DialogFragment主题。

    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:srcCompat="http://schemas.android.com/tools"
        android:id="@+id/place_search_dialog"
        style="?alertDialogTheme"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible">

但是现在即使我在alertDialogTheme属性中设置了"android:windowNoTitle">false</item>,标题文本也没有显示, 为什么会这样?

  <resources >

            <!-- Base Theme -->
            <style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
                <!-- Attributes for all APIs -->
                <item name="windowActionBar">true</item>
                <item name="windowNoTitle">true</item>
                <item name="dialogTheme">@style/AppTheme.Dialog</item>
                <item name="alertDialogTheme">@style/AppTheme.Dialog.Alert</item>
                <!-- Theme for the Preferences -->
                <item name="preferenceTheme">@style/AppPreferenceTheme</item>
            </style>

            <!-- Default App Theme -->
            <style name="AppTheme" parent="BaseTheme">
                <!-- API specific attributes 14+ -->
                <item name="selectableRectDrawable">@drawable/state_list_selectable_rect_black</item>
                <item name="selectableRectDrawableInverse">@drawable/state_list_selectable_rect_white</item>
                <item name="selectableRectDrawableColored">@drawable/state_list_selectable_rect_black</item>
                <item name="selectableRoundedRectDrawable">@drawable/state_list_selectable_rounded_rect_black</item>
                <item name="selectableRoundedRectDrawableInverse">@drawable/state_list_selectable_rounded_rect_white</item>
                <item name="selectableRoundedRectDrawableColored">@drawable/state_list_selectable_rounded_rect_black</item>
            </style>


            <!-- Bohemia App Theme -->
            <style name="BaseTheme.Bohemia" parent="AppTheme">
                <!-- Attributes for all APIs -->
                <item name="colorPrimary">@color/material_bohemia_400</item>
                <item name="colorPrimaryDark">@color/material_bohemia_600</item>
                <item name="colorAccent">@color/material_bohemia_a100</item>
                <item name="dialogTheme">@style/AppTheme.Dialog.Bohemia</item>
                <item name="alertDialogTheme">@style/AppTheme.Dialog.Alert.Bohemia</item>
                <item name="android:windowBackground">@color/material_bohemia_300</item>
                <item name="colorControlHighlight">@color/material_bohemia_a100</item>
                <item name="colorControlActivated">@color/material_bohemia_a100</item>
                <item name="colorControlNormal">@color/material_bohemia_a200</item>
            </style>

            <style name="AppTheme.Bohemia" parent="BaseTheme.Bohemia">
                <!-- API specific attributes 14+ -->
                <item name="selectableRectDrawableColored">@drawable/state_list_selectable_rect_bohemia</item>
                <item name="selectableRoundedRectDrawableColored">@drawable/state_list_selectable_rounded_rect_bohemia</item>
            </style>



            <!-- Red App Theme -->
            <style name="BaseTheme.Red" parent="AppTheme">
                <!-- Attributes for all APIs -->
                <item name="colorPrimary">@color/material_red_500</item>
                <item name="colorPrimaryDark">@color/material_red_700</item>
                <item name="colorAccent">@color/material_red_a700</item>
                <item name="dialogTheme">@style/AppTheme.Dialog.Red</item>
                <item name="alertDialogTheme">@style/AppTheme.Dialog.Alert.Red</item>
                <item name="android:windowBackground">@color/material_red_300</item>
                <item name="colorControlHighlight">@color/material_red_a200</item>
                <item name="colorControlActivated">@color/material_red_a200</item>
                <item name="colorControlNormal">@color/material_red_a200</item>
                <!-- Chat color -->
            </style>

            <style name="AppTheme.Red" parent="BaseTheme.Red">
                <!-- API specific attributes 14+ -->
                <item name="selectableRectDrawableColored">@drawable/state_list_selectable_rect_red</item>
                <item name="selectableRoundedRectDrawableColored">@drawable/state_list_selectable_rounded_rect_red</item>

            </style>





            <!-- Orange App Theme -->
            <style name="BaseTheme.Orange" parent="AppTheme">
                <!-- Attributes for all APIs -->
                <item name="colorPrimary">@color/material_orange_500</item>
                <item name="colorPrimaryDark">@color/material_orange_700</item>
                <item name="colorAccent">@color/material_orange_a700</item>
                <item name="dialogTheme">@style/AppTheme.Dialog.Orange</item>
                <item name="alertDialogTheme">@style/AppTheme.Dialog.Alert.Orange</item>
                <item name="android:windowBackground">@color/material_orange_300</item>
                <item name="colorControlHighlight">@color/material_orange_a200</item>
                <item name="colorControlActivated">@color/material_orange_a200</item>
                <item name="colorControlNormal">@color/material_orange_a200</item>
            </style>

            <style name="AppTheme.Orange" parent="BaseTheme.Orange">
                <!-- API specific attributes 14+ -->
                <item name="selectableRectDrawableColored">@drawable/state_list_selectable_rect_orange</item>
                <item name="selectableRoundedRectDrawableColored">@drawable/state_list_selectable_rounded_rect_orange</item>

            </style>


            <!-- Default Dialog Theme -->
            <style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
            </style>

            <!-- Bohemia Dialog Theme -->
            <style name="AppTheme.Dialog.Bohemia">
                <item name="colorPrimary">@color/material_bohemia_400</item>
                <item name="colorPrimaryDark">@color/material_bohemia_500</item>
                <item name="colorAccent">@color/material_bohemia_a100</item>
            </style>

            <!-- Red Dialog Theme -->
            <style name="AppTheme.Dialog.Red">
                <item name="colorPrimary">@color/material_red_500</item>
                <item name="colorPrimaryDark">@color/material_red_700</item>
                <item name="colorAccent">@color/material_red_a700</item>
            </style>

            <!-- Orange Dialog Theme -->
            <style name="AppTheme.Dialog.Orange">
                <item name="colorPrimary">@color/material_orange_500</item>
                <item name="colorPrimaryDark">@color/material_orange_700</item>
                <item name="colorAccent">@color/material_orange_a700</item>
            </style>



            <!-- Default Alert Dialog Theme -->
            <style name="AppTheme.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
                <item name="android:windowNoTitle">false</item>
            </style>

            <!-- Bohemia Alert Dialog Theme -->
            <style name="AppTheme.Dialog.Alert.Bohemia" >
                <item name="colorPrimary">@color/material_bohemia_400</item>
                <item name="colorPrimaryDark">@color/material_bohemia_500</item>
                <item name="colorAccent">@color/material_bohemia_a100</item>
                <item name="android:background">@color/material_bohemia_400</item>
                <item name="android:textColor">@color/material_bohemia_a200</item>
            </style>

            <!-- Red Alert Dialog Theme -->
            <style name="AppTheme.Dialog.Alert.Red">
                <item name="colorPrimary">@color/material_red_500</item>
                <item name="colorPrimaryDark">@color/material_red_700</item>
                <item name="colorAccent">@color/material_red_a700</item>
                <item name="android:background">@color/material_red_500</item>
            </style>

            <!-- Orange Alert Dialog Theme -->
            <style name="AppTheme.Dialog.Alert.Orange">
                <item name="colorPrimary">@color/material_orange_500</item>
                <item name="colorPrimaryDark">@color/material_orange_700</item>
                <item name="colorAccent">@color/material_orange_a700</item>
                <item name="android:background">@color/material_orange_500</item>
            </style>

        </resources>

0 个答案:

没有答案