styles.xml没有按预期应用

问题描述 投票:0回答:1

因此,我一直在开发一个应用程序,并更改了styles.xml,因此它具有自定义的colorPrimaryDark,colorPrimary和colorAccent。在某些活动中,我还向其主布局添加了android:background="@color/some_color",因此它覆盖了默认布局。

事实是,它正在预览窗口中应用,但是当我在手机上运行它时,颜色保持不变,而不是更改为我要告诉的颜色。

我在做什么错?

这里是我的styles.xml和随机活动的一部分:

styles.xml:

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:fontFamily">@font/montserrat</item>
</style>

活动:

<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="@color/colorPrimaryDark">

android xml background statusbar android-theme
1个回答
0
投票

您只需更改

@ color / colorPrimaryDark

?attr / colorPrimaryDark

<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="?attr/colorPrimaryDark">
© www.soinside.com 2019 - 2024. All rights reserved.