No resource found that matches the given name 'android:Theme.Material'

痞子三分冷 提交于 2019-12-09 03:36:27

问题


After reading this answer, I made RecyclerView ran it on Android 3.0+. But styles.xml in values-v21 still causes the error.

Theme.

<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">

    <!-- Main theme colors -->
    <!-- your app's branding color (for the app bar) -->
    <item name="android:colorPrimary">#f00</item>
    <!-- darker variant of colorPrimary (for status bar, contextual app bars) -->
    <item name="android:colorPrimaryDark">#0f0</item>
    <!-- theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">#00f</item>
</style>

Error.

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material'.

I need to support Android versions from Android 3.0.x (API level 11). <uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L" /> is not a solution.


回答1:


android:Theme.Material is supported only from API level 21. You can see the error message in android studio as below:

android.Theme.Material requires API level 21(current min is 14)



回答2:


If you use the support library, you can safely use those attributes, and they will work (as much as the OS allows) :

<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>


来源:https://stackoverflow.com/questions/25688373/no-resource-found-that-matches-the-given-name-androidtheme-material

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