Установить пользовательскую тему в полноэкранном диалоговом окне - PullRequest
0 голосов
/ 08 мая 2020

Я реализовал темную тему в своем приложении. Но у меня проблема с настройкой полноэкранного диалога. Когда я пытаюсь установить тему, это не влияет на экран диалога.

Вот мои стили. xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorOnPrimary">@android:color/white</item>
        <item name="colorSecondary">@color/colorSecondary</item
        <item name="android:windowBackground">@color/colorPrimary</item>
    </style>

    <style name="DialogTheme" parent="Theme.MaterialComponents.DayNight.Dialog">
        <item name="colorPrimary">@color/colorDanger</item>
        <item name="android:windowBackground">@color/colorPrimary</item>
    </style>
</resources>

Макет моего фрагмента диалога

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:navigationIcon="@drawable/ic_close_white_24dp"
            app:title="Add New"
            app:titleTextColor="@android:color/white" />

    </com.google.android.material.appbar.AppBarLayout>
...

Затем я установил стиль в функции onCreate

class AddNewFinanceDialogFragment : DialogFragment(), OnTimeSelectedListener {
    private lateinit var financeViewModel: FinanceViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.DialogTheme)
        initViewModel()
    }
...

Dialog Background still transparent and style is not applied

Спасибо

...