No resource found that matches the given name (at 'android:color Primary')

时光怂恿深爱的人放手 提交于 2019-12-06 03:11:11

问题


<resources>
  <!-- inherit from the material theme -->
 <style name="AppTheme" parent="android:Theme.Material">
   <!-- Main theme colors -->
   <!--   your app branding color for the app bar -->
   <item name="android:colorPrimary">@color/primary</item>
   <!--   darker variant for the status bar and contextual app bars -->
   <item name="android:colorPrimaryDark">@color/primary_dark</item>
   <!--   theme UI controls like checkboxes and text fields -->
   <item name="android:colorAccent">@color/accent</item>
 </style>
</resources>

Please try to resolve the problem.


回答1:


android:Theme.Material requires API level 21 and so it's cleared that your minSDKVersion is lower than 21.

If you really want to develop app for API 21 then declare android:minSDKVersion=21.

And if in case you want to provide compatibility to lower version then you need to use support library, which is commonly known as AppCompat library.

You can access above attributes using AppCompat:

 <item name=”colorPrimary”>@color/primary</item>
 <item name=”colorPrimaryDark”>@color/primary_dark</item>



回答2:


Actually, you can use this attribute, using the support library:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">

    <item name="colorPrimary">...</item>
</style>

You can also use the others:

    <item name="colorPrimaryDark">...</item>
    <item name="colorAccent">...</item>



回答3:


android:colorPrimary is supported only from API level 21. You can see the error message in android studio and in eclipse below:

android:colorPrimary requires API level 21 (current min is 14)



来源:https://stackoverflow.com/questions/26881072/no-resource-found-that-matches-the-given-name-at-androidcolor-primary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!