Android黑暗主题不设置windowBackground

时间:2017-09-05 17:03:00

标签: java android xml android-layout

我有一个有效的主题,但拒绝设置android:windowBackgorund和android:colorBackground。 其余的代码正常工作,如果我在默认主题中切换项目,它可以正常工作。

styles.xml:

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
    <item name="android:radioButtonStyle">@style/radioLight</item>
</style>

<style name="Dark" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
    <item name="android:windowBackground">@color/grey</item>
    <item name="android:colorBackground">@color/grey</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/soft_grey</item>
    <item name="android:radioButtonStyle">@style/radioDark</item>
</style>

主:

setTheme(R.style.Dark);

不知道它是否无用 activity_main xml:

    <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:scrollbars="none"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="35dp" />

</android.support.design.widget.AppBarLayout>

我犯了什么可耻的错误?

1 个答案:

答案 0 :(得分:1)

android:windowBackground只接受抽奖。尝试将其更改为

<item name="android:windowBackground">@drawable/abc</item>

并创建一个文件abc.xml,例如

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/grey"/>
</shape>

只是检查,你是否在致电super.onCreate()之前致电setTheme?