Android AppCompat requires API level 11

元气小坏坏 提交于 2019-12-30 08:13:10

问题


I have an app that uses the AppCompat support libary for ActionBars. Now I tried to create a new themes.xml file with some style for that purpose.

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

So just the same way it is done here: http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample However, Eclipse throws an error here and says:

android:actionBarStyle requires API level 11 (current min is 8) themes.xml

How can this be as I am using the support libary?


回答1:


Add the below in styles.xml under res/values-14

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:background">#FFFFFF</item>

</style>

You would then need add the following into the values folder: res/values/styles.xml

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="background">#FFFFFF</item>
</style>

For more details

http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

Notice the change for API level 14+

 <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

To API level 7-13

 <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>


来源:https://stackoverflow.com/questions/20032138/android-appcompat-requires-api-level-11

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