Dark activity dialog theme not working

Viewed 1500

I want to have a dark activity dialog theme, so I define following:

<style name="AppThemeDialogActivityDark" parent="Theme.AppCompat.Dialog">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- dark toolbar + dark popup menu -->
    <item name="toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>


    <!-- trying to forcefully set the background and text color -->
    <item name="android:windowBackground">@android:color/background_dark</item>
    <item name="android:textColor">@color/white</item>

    <item name="android:minWidth">320dp</item>

    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Activity:

public class FeedbackActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // darkTheme returns true!!!
        setTheme(MainApp.getPrefs().darkTheme() ? R.style.AppThemeDialogActivityDark : R.style.AppThemeDialogActivity);
        super.onCreate(savedInstanceState);

        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_feedback);
    }
}

Layout:

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

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            app:theme="?toolbarTheme"/>

        <ListView
            android:padding="12dp"
            android:id="@+id/lvFeedback"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ScrollView
            android:id="@+id/svFeedback"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="0dp">

                <TextView
                    android:padding="12dp"
                    android:id="@+id/tvFeedback"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

        </ScrollView>

        <Button
            android:padding="12dp"
            android:id="@+id/btButton"
            style="?borderlessButtonStyle"
            android:elevation="4dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</layout>

What am I missing here? Why does my activity dialog have a white background instead of the dark one???

EDIT - Interesting details

  • Setting the views backgrounds to android:background="?android:windowBackground" does work. But I have to do this for the ListView and for the TextView. That this theme attribute works means, the theme is applied correctly, seems like the default background is defined in another theme attribute in a dialog theme?
  • my ListView items are themed correctly as well by simply using android.R.layout.simple_list_item_1 as layout, I don't need to set their background/text colors, they are correctly themed for a dark theme, but not visible if I don't set the ListView background manually like above
1 Answers
Related