Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

material design - Android Theme - "Cannot resolve symbol" error on statusBarColor item

In my Android (API 30) app theme (file themes.xml) using MaterialComponents the "android:statusBarColor" works but displays the following error in red :Cannot resolve symbol 'android:statusBarColor'

You can reproduce this by creating a new android projet with the "Tabbed Activity" template :

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.AppTest" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color.  IN RED - "Cannot resolve symbol" below  -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>  
        <!-- Customize your theme here. -->
    </style>

In fact, all android items in themes produce this Cannot resolve symbol, like :

<style name="ToolbarPopupTheme" parent="ThemeOverlay.MaterialComponents">
    <!--   android:background below in RED-->
    <item name="android:background">?attr/colorPrimary</item>
</style>

If any of you have any insight on this, it would be great.

question from:https://stackoverflow.com/questions/65858339/android-theme-cannot-resolve-symbol-error-on-statusbarcolor-item

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

android:statusBarColor is introduced in API level 21. So, If You are trying to use this property in default styles.xlm. You will get Cannot resolve symbol.

You can create styles.xml in values-v21 folder and there you can use this attribute without any error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...