Applying a theme to v7 Support Action Bar

三世轮回 提交于 2019-12-09 18:01:16

问题


I am using the support v7 library to implement ActionBar in my app..I have this in my styles.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBarTheme</item>
    </style>
    <style name="ActionBarTheme" parent="android:Widget.ActionBar">
        <item name="android:background">#FFFF0000</item>
    </style>
</resources>

However, Eclipse complains in the actionBarStyle line. The error is this one:

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

What can I do to apply my theme to API levels 8-10?


回答1:


You need to provide two API specific styles.xml. In your values/styles.xml use

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarStyle">@style/ActionBarTheme</item>
</style>

and in your values-v14/styles.xml use

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBarTheme</item>
</style>



回答2:


If you use latest v7 support library (v21 at the time of this post), there is no need to add android: prefix to any action bar attributes anymore.

In your case, adding the following to values/styles.xml will be sufficient:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/ActionBarTheme</item>
</style>

Reference: https://chris.banes.me/2014/10/17/appcompat-v21/#migration-from-previous-setup



来源:https://stackoverflow.com/questions/18307622/applying-a-theme-to-v7-support-action-bar

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